iphone - Facebook iOS SDK 3.1 在 friend 墙上发布图片错误

标签 iphone objective-c ios facebook post

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

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

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

它工作正常。

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

最佳答案

发生这种情况是因为您没有足够的权限级别。 正如 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”,它“使您的应用程序能够向用户的流和用户的 friend 的流发布内容、评论和点赞。这是一个超集发布权限,它还包括 publish_actions。”(c)

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

这意味着您必须分两步请求适当的权限。先学基础再求高级。

关于iphone - Facebook iOS SDK 3.1 在 friend 墙上发布图片错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13817590/

相关文章:

iphone - iOS5 和 iOS 5.1 中按钮上缺少字体文本

iphone - 在所有 View Controller 中使用 AudioUnit 初始化

objective-c - UIBarButtonItem with UIButton as CustomView - 从 UIButton,如何访问它的 UIBarButtonItem?

ios - 企业 ios 应用程序中的崩溃日志

iphone - 水平 UITableView

iPhone 应用程序在 main.m 中崩溃,没有更多信息..?

ios - 阻止嵌入的 UITableView 垂直偏移

objective-c - 如何设置 NSTableCellView 的背景颜色?

带有 iOS 8 (Xcode 6) 的 iOS 模拟器没有出现在 Safari 开发菜单中

ios - 不鼓励在分离的 View Controller 上呈现 View Controller