【问题标题】:Getting "Unsupported FBSDKGraphRequest attachment" when posting photo with tags发布带有标签的照片时获取“不支持的 FBSDKGraphRequest 附件”
【发布时间】:2015-04-24 18:53:32
【问题描述】:

我一直在尝试使用 FBSDKGraphRequest 上传带有标题和标签的朋友的照片,但我真的很难让标签正常工作。这是我得到的:

NSDictionary *parameters = @{
                             @"caption" : message,
                             @"picture" : UIImagePNGRepresentation(image),
                             @"tags"    : @[@{@"tag_uid": @902893713061742, @"x":@0.0, @"y":@0.0},
                                            @{@"tag_uid": @902486513129784, @"x":@10.0, @"y":@10.0}],
                             };

FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:parameters tokenString:token.tokenString version:@"v2.3" HTTPMethod:@"POST"];
[connection addRequest:request completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    if(error)
        NSLog(@"%@", error);
    else
        NSLog(@"Success");
}];
[connection start];

但是每次我尝试运行它都会抛出这个错误:

FBSDKLog:不支持的 FBSDKGraphRequest 附件:(
{
"tag_uid" = 902893713061742;
x = 0;
y = 0;
},
{
"tag_uid" = 902486513129784;
x = 10;
y = 10;
}
),跳过。

我已经尝试了几种不同的方法来附加 @"tags" 信息,但没有一种方法能完成这项工作。有谁知道这样做的正确方法?这甚至可能吗? https://developers.facebook.com/docs/graph-api/reference/user/photos/ 让我这么想。

编辑:尝试在没有标签的情况下发布,然后用它们更新帖子 ID,但仍然没有成功:(

【问题讨论】:

    标签: ios xcode facebook facebook-graph-api facebook-sdk-4.0


    【解决方案1】:

    您不能使用相同的 FBSDKGraphRequest 上传带有标题和标记朋友的照片。您必须为不同的任务调用不同的方法,如下所示:

    对于像标题和标签这样的消息:

    if ([FBSDKAccessToken currentAccessToken]){
     NSDictionary *params = @{
                            @"message": @"This is a test message",
                           };
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/feed" parameters:params HTTPMethod:@"POST"]startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
            if (error)
             NSLog(@"error:%@", error);
            else{
                UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"FBSDKGraphRequest" message:@"Text Shared successfully..!" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
                [av show];
                }
     }];
    }
    

    发布照片:

    if ([FBSDKAccessToken currentAccessToken]){
    NSDictionary *params = @{@"sourceImage":UIImagePNGRepresentation(pickedImage)};
    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
        if (!error) {
            UIAlertView *av = [[UIAlertView alloc]initWithTitle:@"FBSDKGraphRequest" message:@"Image Shared successfully..!" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil, nil];
            [av show];
        } else {
            NSLog(@"Graph API Error: %@", [error description]);
        }
      }];
    }
    

    希望对您有所帮助...:)

    【讨论】:

    • 感谢您的回答,但这仍然不能解决我的问题。我想发布一张照片并在同一个帖子中标记几个朋友。不过没关系,这似乎根本不适用于当前版本的 Graph API。 Instagram 确实做到了这一点,我不知道是怎么做到的,这让我有点难过。
    【解决方案2】:

    您可以上传带有标题的照片,只需将“标题”键更改为“消息”

    if FBSDKAccessToken.currentAccessToken().hasGranted("publish_actions") {
         let params: [NSObject : AnyObject] = ["message": "Caption", "sourceImage" : UIImagePNGRepresentation(image)]
         FBSDKGraphRequest(graphPath: "me/photos", parameters: params, HTTPMethod: "POST").startWithCompletionHandler({ (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
                // Handle result
         })
    }
    

    【讨论】:

      【解决方案3】:

      这是帮助您入门的基本代码:

      if (![FBSDKAccessToken currentAccessToken]) {
                  [self alertWithMessage:@"Log into FB and request publish_actions" title:@"Upload Failed"];
                  return;
              }
      NSDictionary *params = @{@"source":UIImagePNGRepresentation([UIImage imageNamed:@"snoopy.png"])};
      
      [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/photos" parameters:params HTTPMethod:@"POST"] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                  if (!error) {
                      [self alertWithMessage:[NSString stringWithFormat:@"Result: %@", result] title:@"Post Photo Success!"];
                  } else {
                      NSLog(@"Graph API Error: %@", [error description]);
                  }
              }];
      

      这保证可以工作,因为我自己测试过。请记住检查您拥有的访问令牌是否具有 publish_actions 权限,因为这也可能会影响您是否可以上传人们的图片。

      【讨论】:

      • 但此方法不沿图像共享文本。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多