用户图像为Open Graph对象 - iOS

时间:2013-05-08 10:48:37

标签: ios facebook facebook-graph-api

我正在尝试创建一个Open Graph Object,将用户生成的照片上传到登台资源,以便用它发布一个Action。我正在使用适用于iOS的最新Facebook SDK(3.5)。 代码如下:

[FBRequestConnection startForUploadStagingResourceWithImage:self.image completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        if (!error){
            NSString *uri = [result valueForKey:@"uri"];

            NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
            object.provisionedForPost = YES;
            object[@"type"] = @"<APP_NAME>:<OBJECT_NAME>";
            object[@"url"] = uri;
            object[@"title"] = @"My Title";
            object[@"user_generated"] = @"true";

            [FBRequestConnection startForPostOpenGraphObject:object
                                           completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

    }];
}];

startForPostOpenGraphObject的完成块中,我应该使用新创建的Object的id调用 startForPostWithGraphPath 。但是,我没有id,但是错误:

Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x1f2f14a0 {com.facebook.sdk:HTTPStatusCode=500, com.facebook.sdk:ParsedJSONResponseKey={
body =     {
    error =         {
        code = 1;
        message = "An unknown error has occurred.";
        type = OAuthException;
    };
};
code = 500;
}, com.facebook.sdk:ErrorSessionKey=<FBSession: 0x1f2ca300, state: FBSessionStateOpen, loginHandler: 0x1f2cb750, appID: **************, urlSchemeSuffix: , tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0x1e56ed00>, expirationDate: 4001-01-01 00:00:00 +0000, refreshDate: 2013-05-08 09:07:56 +0000, `attemptedRefreshDate`: 0001-12-30 00:00:00 +0000, permissions:(
"user_photos",
"publish_stream",
"publish_actions"
)>}

我做错了什么?

1 个答案:

答案 0 :(得分:0)

url和user_generated属性都需要放在image属性下,这也是一个数组,所以这样的东西应该可以工作:

object[@"type"] = @"<APP_NAME>:<OBJECT_NAME>";
object[@"title"] = @"My Title";
object[@"image"] = @[@{@"url": uri, @"user_generated":@"true"}];

您还可以看到关于如何在批量请求中执行此操作的美味示例。