【问题标题】:Facebook return com.facebook.sdk error 5 during Friend Wall PostFacebook 在 Friend Wall Post 期间返回 com.facebook.sdk 错误 5
【发布时间】:2013-05-24 10:00:01
【问题描述】:

在我的应用程序中,我使用了 Facebook sdk 3.1,并尝试使用它来做墙贴。 使用此代码片段,我可以成功地将图像和消息发布到朋友墙和我自己的墙上。我只需更改 me/photosfriendId/photos

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

        }
    }
}

对于消息墙帖子,我使用 me/feed 和它的工作,但对于朋友 friendID/feed 将给我 错误:HTTP 状态代码:403 并在警告框中我得到 com.facebook.sdk 错误 5

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

【问题讨论】:

  • 我认为您没有激活所有权限。
  • 参见developers.facebook.com/docs/reference/api/publishing - 上面写着“注意:如果您要发布到朋友的时间线或墙上,则必须使用 Feed 对话框。”所以你不能发布friendId/feed。为此,您需要使用提要对话框。
  • @CAbernathy : 谢谢它非常有用

标签: iphone ios facebook facebook-graph-api


【解决方案1】:

这里是解决方案,

我将我的 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){}];

我得到了对话框,点击分享后成功在朋友的墙上发帖。

希望这个 sn-p 可以帮助其他人。

【讨论】:

  • 感谢您的有用提示。@ C Abernathy
  • @Harin 有没有办法在后台发帖?不显示对话框?
【解决方案2】:

我不确定。试试这个:

me?fields=friends.fields(feed)

【讨论】:

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