简体   繁体   中英

Facebook iOS SDK 3.1 post image on friends wall error

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:

Insufficient_scope The request requires higher privileges than provided by the access token. The resource server SHOULD respond with the HTTP 403 (Forbidden) status code and MAY include the "scope" attribute with the scope necessary to access the protected resource.

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.

你必须检查你的Facebook应用程序ID有时问题创建与它.Cos我有相同的问题发布墙给我的朋友墙但更改Facebook应用程序ID和它的工作完美。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM