当前位置:  开发笔记 > 编程语言 > 正文

Facebook在Friend Wall Post期间返回com.facebook.sdk错误5

如何解决《Facebook在FriendWallPost期间返回com.facebook.sdk错误5》经验,为你挑选了1个好方法。

在我的应用程序中我使用Facebook sdk 3.1并使用它我尝试做墙贴.使用此代码片段,我可以在Friend Wall和我自己的墙上成功发布图像和消息.我只需更改我/照片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 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];
                 }
             }];

        }
    }
}

对于留言墙帖我使用了我/ feed及其工作,但对于朋友friendID/feed会给我错误:HTTP状态代码:403和在警告框中我得到了com.facebook.sdk错误5.

所以,请指导我,我做错了什么?,或者我必须为墙贴做些什么.



1> Harin..:

这是解决方案,

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

#import 

然后更新

[[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的墙上.

希望这段代码可以帮助别人.

推荐阅读
帆侮听我悄悄说星星
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有