2012-12-11 83 views
0

我正在使用最新的Facebook iOS SDK 3.1.1 ,同时尝试在朋友墙上张贴UIImage我得到错误5(错误:HTTP状态码:403)。Facebook iOS SDK 3.1在朋友墙上张贴图片错误

如果我尝试在我的墙上发布图片,但它的效果不错,但不是我的朋友之一。

我的代码: 1.张贴我检查用户是否具有正确的权限之前,当他做我正在做

-(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]; 
      } 
     }]; 



    } 
} 
} 

提,如果我改变

startWithGraphPath:[NSString stringWithFormat:@"%@/photos",userID]

startWithGraphPath:[NSString stringWithFormat:@"me/photos",userID] 

其工作o ķ。

我在做什么错? 我一直在寻找答案,但没有任何帮助。 谢谢!

回答

2

发生这种情况是因为您的权限级别不足。 作为FB文件说:

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.

您必须获得高级权限张贴到其他用户的墙。您需要的权限是@“publish_stream”,它允许您的应用程序将内容,评论和喜欢发布到用户的流和用户朋友的流中,这是超集发布权限,其中还包括publish_actions。“(c)

最新的变化迫使你所需的权限划分到两个级别 - 基本,让您了解用户和基本信息先进(岗位等) 这里的权限列表: Extended permissions list

这意味着您必须分两步请求适当的权限。首先获得基本,然后要求提前。

+0

哇! 谢谢你!我甚至不能说我多么感激它!它工作得很好! 为我节省了很多时间:) – user1526725

+0

一点都不,你应该接受答案,如果它帮助你。点击票数附近的复选标记。 – Stas

0

你必须检查你的Facebook应用程序ID有时候会用它创建问题。我有同样的问题将墙贴到我的朋友墙上,但更改Facebook应用程序ID和它的工作完美。

相关问题