iphone - 在Friend Wall发表期间Facebook返回com.facebook.sdk错误5

标签 iphone ios facebook facebook-graph-api

在我的应用程序中,我使用了Facebook sdk 3.1,并尝试使用它进行贴墙。
使用此代码段,我可以成功地在 friend 墙上和我自己的墙上张贴图像和消息。我只需更改我/照片friendId /照片

-(IBAction)postPhoto:(id)sender
{
    UIImage *image=[UIImage imageNamed:@"baby.jpg"];
    NSArray *frndArray=[[NSArray alloc] initWithObjects:@"Friend ID", nil];
    [self postImageOnFriendsWall:image FriendsArray:frndArray];
}

-(void)postImageOnFriendsWall:(UIImage*)image FriendsArray:(NSArray*)friends
{
    AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];


    // if we don't have permission to announce, let's first address that
    if ([appDelegate.session.permissions  indexOfObject:@"publish_actions"] == NSNotFound)
    {

        NSArray *permissions =[NSArray arrayWithObjects:@"publish_actions",@"publish_stream",@"manage_friendlists", nil];

        [FBSession setActiveSession:appDelegate.session];

        [[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error)
         {
             if (!error)
             {
                 // 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
    {

        //post image
        for (id<FBGraphUser> user in friends)
        {

            NSString* szMessage = @"Check out!";

            NSString *userID = user;
            NSLog(@"trying to post image of %@ wall",userID);
            NSMutableDictionary  *postVariablesDictionary = [[NSMutableDictionary alloc] init];
            [postVariablesDictionary setObject:UIImagePNGRepresentation(image) forKey:@"picture"];
            [postVariablesDictionary setObject:szMessage 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];
                 }
             }];

        }
    }
}

对于Message wall post,我使用了 me / feed 及其工作,但是对于Friend ,friendID / feed 将给我错误:HTTP状态码:403 ,在警报框中,我得到了 com.facebook.sdk错误5

所以,如果我做错了什么,请指导我?或我在墙上留言时要做的事情。

最佳答案

这是解决方案,

我将FB SDK 3.1更新为3.2,然后导入

#import <FacebookSDK/FacebookSDK.h>

然后更新
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends
                                                   completionHandler:^(FBSession *session, NSError *error) {}];

代替
[[FBSession activeSession] reauthorizeWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceFriends completionHandler:^(FBSession *session, NSError *error){}];

并更新
 NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                           @"FRIEND ID", @"to",
                                           @"text change", @"caption",
                                           @"this is test message on ur wall", @"description",
                                           @"https://website.com/share", @"link",
                                           @"http://website.com/iossdk_logo.png", @"picture",
                                           nil];
            [FBWebDialogs presentFeedDialogModallyWithSession:nil
                                                   parameters:params
                                                      handler:
             ^(FBWebDialogResult result, NSURL *resultURL, NSError *error)

            {}];

代替
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"%@/photos",userID] parameters:postVariablesDictionary HTTPMethod:@"POST" completionHandler:^(FBRequestConnection *connection, id result, NSError *error){}];

我得到了对话框,然后单击共享后成功在FRIEND的墙上发布。

希望此摘要可以帮助其他人。

关于iphone - 在Friend Wall发表期间Facebook返回com.facebook.sdk错误5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16732352/

相关文章:

facebook - 无法创建 Facebook 应用 - 稍后重试

iphone - 如何在 xcode 中重新启用 CoreLocation 提示?

iphone - 如何在 Xcode 中的注释上设置默认名称和公司名称?

iphone - 核心数据获取属性。更新后刷新

ios - 在第一次应用程序加载时从 Preference Bundle 初始化 IOS Preferences

Android me/invitable_friends facebook api 获取短ID

javascript - 如何使登录使用facebook手动触发

iOS 8.4 特定 : AVPlayer not playing both video & audio and no errors

iphone - UITextField 文本未出现在中心

ios - AirPlay 到 Apple TV 全屏