【问题标题】:Got an error when post message with image on facebook在 Facebook 上发布带有图片的消息时出错
【发布时间】:2016-04-11 08:51:01
【问题描述】:

请帮我解决以下错误:

Error Domain=com.facebook.sdk Code=5 "(null)" UserInfo={com.facebook.sdk:ParsedJSONResponseKey={
        body =     {
            error =         {
                code = 2500;
                "fbtrace_id" = "HkQ+T3pxGRU";
                message = "An active access token must be used to query information about the current user.";
                type = OAuthException;
            };
        };
        code = 400;
    }, com.facebook.sdk:HTTPStatusCode=400}

我在 facebook 上发布带有图片的消息时出现错误,我正在使用最新的 facebook sdk。

我正在使用以下代码:

    -(void)posting
     {
       if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
         NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
         [params setObject:@"hello hii how r u " forKey:@"message"];
         [params setObject:UIImagePNGRepresentation(self.img_to_share.image) forKey:@"picture"];
         [FBRequestConnection startWithGraphPath:@"me/photos"
                                      parameters:params
                                      HTTPMethod:@"POST"
                               completionHandler:^(FBRequestConnection *connection,
                                                   id result,
                                                   NSError *error)
          {
              if (error)
              {
                  //showing an alert for failure
                  NSLog(@"Unable to share the photo please try later.");
              }
              else
              {
                  //showing an alert for success
                  NSLog(@"Shared the photo successfully");
              }
          }];

     }
}

提前致谢,

【问题讨论】:

  • 添加相关代码。
  • "An active access token must be used to query information about the current user." 是用户登录fb吗?
  • 是的,用户已经登录 fb @AnilVarghese

标签: ios objective-c facebook facebook-graph-api facebook-ios-sdk


【解决方案1】:

编辑:

在图形调用中添加 access_token 后检查,因为 facebook-ios-sdk 不会自动执行此操作。

[FBRequestConnection requestWithGraphPath:[NSString stringWithFormat:@"/me/photos?access_token=%@", FBRequestConnection.accessToken]
  andParams:params andHttpMethod:@"POST" andDelegate:self];

更多信息请查看:https://developers.facebook.com/docs/graph-api/reference/user#posts

【讨论】:

  • 不要在图片参数中传递图片数据,只在“图片”中传递图片的url。@Moni_BQ
  • 不工作。如果我通过“图片网址”,应用程序将崩溃
猜你喜欢
  • 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
相关资源
最近更新 更多