Example Facebook object code.

泄露秘密 提交于 2019-12-05 21:52:59

I've ran into the same issue. You first need to post the object, then get its ID, and provide the object ID instead of the object itself:

NSMutableDictionary<FBOpenGraphObject> *object = [...];
[FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                if(result != nil){
                    NSString* resultID = [result objectForKey:@"id"];
                    [FBRequestConnection startForPostWithGraphPath:@"me/objects/sotd_facebook:new_zombie"
                               graphObject:resultID //...

The object is first posted as an object to Facebook, then you can use the action (new_zombie) on the object. I'm also in the exact same situation (with July 2013 breaking changes enabled) trying to figure out to create all in one step on Facebook, but couldn't figure it out without using a seperate, self-hosted webserver. In my issue, I'm getting an error about the object being already posted and can't be posted again. If you don't have this issue, you can go on with this one now.

It seems that the error itself is caused by the fbsdk:create_object key (and its value 1) in the object dictionary. This key is automatically added by Facebook SDK into the object. When I removed this key explicitly before posting, it did not throw an exception on post, but my answer about posting the object still applies. Even if you remove that key, you'll be getting an OAuthException at the server side, telling that the object is not a "reference". I'd be really glad to be proven wrong about this, though.

I just added these lines before API call and that works fine!

    object[@"create_object"] = @"1";
    object[@"fbsdk:create_object"] = @"1";

It seems this is a bug in Facebook SDK! it tries to encode Boolean value

Sample code should be something like this

    NSMutableDictionary<FBGraphObject> *object =
        [FBGraphObject openGraphObjectForPostWithType:@"{YOUR NAMESPACE}:{YOUR OBJECT TYPE}"
                                                title:@"title"
                                                image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png"
                                                  url:@"http://samples.ogp.me/192059197639963"
                                          description:@"description"];

    object[@"create_object"] = @"1";
    object[@"fbsdk:create_object"] = @"1";

    [FBRequestConnection startForPostWithGraphPath:@"me/objects/{YOUR NAMESPACE}:{YOUR OBJECT TYPE}"
                                       graphObject:object
                                 completionHandler:^(FBRequestConnection *connection,
                                                     id result,
                                                     NSError *error) {
                                     NSLog(@"%@",result);
                                 }];
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!