在iOS 7和SDK 3.10更新后,Facebook应用程序停止发布朋友照片

时间:2013-12-10 18:26:10

标签: ios iphone facebook facebook-graph-api

我正在创建一个简单的iOS应用程序,它会拍照,修改它并将其发布到您的某些朋友帐户上。在“分享”命令中,该应用程序将显示FB FriendPicker,让您选择一位朋友。

当我使用iOS 6和FB SDK~3.7时,我有这个工作,工作代码如下:

NSString* friendId;
for (id<FBGraphUser> user in self.friendPickerController.selection) {
    friendId = user.id;
}

AppDelegate * appDelegate = (AppDelegate*) [ [UIApplication sharedApplication] delegate ];
UIImage *img = appDelegate.imageAnalyzed;

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
[params setObject:@"Some message" forKey:@"message"];
[params setObject:UIImagePNGRepresentation(img) forKey:     //@"source"];  //I tried all of them...
                                                        @"image"];
                                                            //@"picture"];
[params setObject:@"true" forKey: @"fb:explicitly_shared"];

NSString* strId = [NSString stringWithFormat:@"%@/photos", friendId];

[FBRequestConnection startWithGraphPath: strId
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)   
  {
     if (error)
     {
         //showing an alert for failure
         [self showAlert:@"Error posting photo." result:result error:error];
     }
     else
     {
         [self performSegueWithIdentifier:@"goToAfterFBSegue" sender:self];
     }
 }];

所以这就是问题:

当我将iOS升级到7.0并将Facebook SDK升级到3.10时,此代码停止工作。但是当我更换:

NSString* strId = [NSString stringWithFormat:@"%@/photos", friendId];

使用:

NSString* strId = @"me/photos";

它可以工作并将图片添加到我的帐户中。我试图在FB上找到与最近更改相关的任何内容,但官方文档说从那时起没有任何功能更改,只有'错误修复'。

我还发现了另一个代码示例,它使用 startForPostWithGraphPath 而不是 startWithGraphPath ,如下所示:

NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
[action setObject:@"From Friendalizer:" forKey:@"message"];
[action setObject:UIImagePNGRepresentation(img) forKey:   //  @"source"];
                                                            @"image" ];
                                                        //@"picture"];

[FBRequestConnection startForPostWithGraphPath: @"me/myapp:post"
                                   graphObject:action
                             completionHandler:^(FBRequestConnection *connection,
                                                 id result,
                                                 NSError *error)

此代码也给我错误,区别在于第一个版本中的错误是“com.facebook.sdk:ErrorSessionKey”,HTTPStatusCode 403,第二个版本返回HTTPStatusCode 400:]。

你知道如何解决这个问题吗?

顺便说一句:我明白这对你们中的某些人来说可能是一个愚蠢或错误描述的问题,但这是我的第一个iOS应用程序和第一个FB应用程序,所以我觉得我会在这里失明...

1 个答案:

答案 0 :(得分:1)

截至目前(as per the latest Facebook API)已删除使用图表路径发布到朋友留言墙的信息。只有我们可以分享朋友墙的图像才能使用Feed对话方法

-(void)postToFriendsWall{

    NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
    NSString *greetingMessage = [self greetingTextView].text;

     // Set the Friends ID here in dictionary
    [dictionary setObject:fbUserDAO.uID forKey:@"to"];

     // Add Link attributes
    [dictionary setObject:@"www.github.com" forKey:@"link"];
    //[dictionary setObject:@"ADD_CAPTION" forKey:@"caption"];
    [dictionary setObject:@"Go for Git" forKey:@"name"];
    [dictionary setObject:@"A repository for all..." forKey:@"description"];


       NSString *imageURL = @"https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png";

         //  embedded action along with Like, Comment and Share
        NSString *actionsString = [[NSString alloc]initWithFormat:@"[{'name': 'Show Card', 'link': '%@'}]",imageURL];
        [dictionary setObject:actionsString forKey:@"actions"];
        [dictionary setObject:imageURL forKey:@"picture"];

       [self showFeed:dictionary];
}

然后使用以下代码

显示提要对话框
-(void)showFeed:(NSDictionary *)paramDict{

   [FBWebDialogs presentFeedDialogModallyWithSession:[FBSession activeSession]
                                           parameters:paramDict
                                              handler:
     ^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
         for (UIView *currentView in self.tabBarController.selectedViewController.view.subviews) {

             if ([currentView isKindOfClass: [LoadingView class]]) {
                 [currentView removeFromSuperview];
             }

         }

         if (error) {
     NSLog("An error"); 
     }
}

以下是您希望在朋友留言板上发布的Feed对话框输出(Image link

enter image description here