I am using the latest Facebook iOS SDK 3.1.1 while trying to post UIImage on friends wall i`m getting error 5 (Error: HTTP status code: 403).
if i try to post the image on MY wall its working well, but not of one of my friends.
My Code: 1. before posting i am checking if the user has the right permissions, when he does i am making
-(void)postImageOnFriendsWall:(UIImage*)image FriendsArray:(NSArray*)friends
{
// if we don't have permission to announce, let's first address that
if ([FBSession.activeSession.permissions indexOfObject:@"publish_actions"] == NSNotFound)
{
[FBSession.activeSession reauthorizeWithPublishPermissions:[NSArray arrayWithObject:@"publish_actions"]
defaultAudience:FBSessionDefaultAudienceFriends
completionHandler:^(FBSession *session, NSError *error)
{
if (!error)
{
// re-call assuming we now have the permission
[self postImageOnFriendsWall:image FriendsArray:friends];
}
else
{
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}];
}
else
{
// can post image
for (id<FBGraphUser> user in friends)
{
NSString *userID = user.id;
NSLog(@"trying to post image of %@ wall",userID);
NSMutableDictionary *postVariablesDictionary = [[NSMutableDictionary alloc] init];
[postVariablesDictionary setObject:UIImagePNGRepresentation(image) forKey:@"picture"];
[postVariablesDictionary setObject:@"my image" forKey:@"message"];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",userID] parameters:postVariablesDictionary HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
{
if (error)
{
//showing an alert for failure
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Facebook" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
else
{
//showing an alert for success
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Facebook" message:@"Shared the photo successfully" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alertView show];
}
}];
}
}
}
to mention, if i change
startWithGraphPath:[NSString stringWithFormat:@"%@/photos",userID]
to
startWithGraphPath:[NSString stringWithFormat:@"me/photos",userID]
its working ok.
what am i doing wrong? i have been trying to look for answers but nothing helped. Thank you!
This happens because you have insufficient permissions level. As FB docs say:
You must obtain advanced permissions to post to another user's wall. The permission you need is @"publish_stream" which "enables your app to post content, comments, and likes to a user's stream and to the streams of the user's friends. This is a superset publishing permission which also includes publish_actions."(c)
The latest changes force you to divide the permissions needed onto two levels - basic which allows you to read basic information about the user and advanced (post, etc.) Here's permissions lists: Extended permissions list
This means that you have to ask for appropriate permissions into two steps. First obtain basic and then ask for advanced.
You have to check your facebook Application id sometimes problem create with it.Cos I have same problem to post wall to my friends wall but change facebook Application id and its work perfect.