【问题标题】:Facebook iOS SDK 3.1 post image on friends wall errorFacebook iOS SDK 3.1 在朋友墙上发布图像错误
【发布时间】:2012-12-11 09:51:10
【问题描述】:

我正在使用最新的 Facebook iOS SDK 3.1.1 尝试在朋友墙上发布 UIImage 时出现错误 5(错误:HTTP 状态代码:403)。

如果我尝试将图像张贴在我的墙上,效果很好,但不是我的一个朋友。

我的代码: 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]

它工作正常。

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

【问题讨论】:

    标签: iphone objective-c ios facebook post


    【解决方案1】:

    发生这种情况是因为您的权限级别不足。 正如 FB 文档所说:

    Insufficient_scope 请求需要的权限高于 由访问令牌提供。资源服务器应该响应 HTTP 403 (Forbidden) 状态码,并且可以包含“范围” 具有访问受保护资源所需范围的属性。

    您必须获得高级权限才能在其他用户的墙上发帖。您需要的权限是 @"publish_stream",它“使您的应用能够将内容、cmets 和喜欢发布到用户的流和用户朋友的流中。这是一个超集发布权限,还包括 publish_actions。”(c)

    最新的更改迫使您将所需的权限划分为两个级别 - 基本允许您阅读有关用户的基本信息和高级(帖子等) 这是权限列表: Extended permissions list

    这意味着您必须分两个步骤请求适当的权限。先学基础,再求进阶。

    【讨论】:

    • 哇!谢啦!我什至不能说我是多么感激它!效果很好!节省了我很多时间:)
    • 完全没有,如果它对您有帮助,您应该接受答案。单击选票附近的复选标记。
    【解决方案2】:

    您必须检查您的 facebook 应用程序 ID 有时会出现问题。因为我有同样的问题将墙发布到我的朋友墙但更改 facebook 应用程序 ID 并且它的工作完美。

    【讨论】:

      猜你喜欢
      • 2013-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      相关资源
      最近更新 更多