Facebook Object Code Example.

This is an example of the code I get from Facebook to use custom objects. I created this with a special action to use the Facebook story.
Documentation for Facebook:
https://developers.facebook.com/docs/opengraph/overview/

NSMutableDictionary<FBGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:@"sotd_facebook:new_zombie" title:@"Sample New Zombie" image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png" url:@"http://samples.ogp.me/191078581053171" description:@""];; [FBRequestConnection startForPostWithGraphPath:@"me/objects/sotd_facebook:new_zombie" graphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { // handle the result }]; 

I am curious how I can use this object for action in sos IOS for IOS. I tried using the following codes and crashing while creating an FBRequestConnection.

 [__NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to instance 0x3af00530 Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to instance 0x3af00530' 

[edit]
I created a FBOpenGraphObject and use the FBRequestConnection startForPostOpenGraphObject: completeHandler method. In the completion handler, I extract the identifier from the result and put it in another FBOpenGraphObject with the identifier. and he is still falling.

 NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPostWithType:@"sotd_facebook:new_zombie" title:@"Sample New Zombie" image:@"https://fbstatic-a.akamaihd.net/images/devsite/attachment_blank.png" url:@"http://samples.ogp.me/191078581053171" description:@""]; [FBRequestConnection startForPostOpenGraphObject:object completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { // handle the result // handle the result if (error) { NSLog(@"Error sharing story: %@", error.localizedDescription); } else if(result != nil) { NSLog(@"Result: %@", result); NSString* resultID = [result objectForKey:@"id"]; NSMutableDictionary<FBOpenGraphObject> *newObject = [FBGraphObject openGraphObjectForPost]; newObject.id = resultID; [FBRequestConnection startForPostWithGraphPath:@"me/objects/sotd_facebook:new_zombie" graphObject:newObject completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { // handle the result // handle the result if (error) { NSLog(@"Error sharing story: %@", error.localizedDescription); } else { NSLog(@"Result: %@", result); } }]; } }]; 

Crash Log:

2013-08-16 18: 47: 11.013 ZombieBlackout [3408: 907] - [__ NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to instance 0x3a118530 2013-08-16 18: 47: 11.015 ZombieBlackout [3408: 907] * Application termination due to the uncaught exception "NSInvalidArgumentException", reason: '- [__ NSCFBoolean dataUsingEncoding:]: unrecognized selector sent to example 0x3a118530'

+3
source share
2 answers

I ran into the same problem. First you need to publish the object, then get its identifier and provide the identifier of the object 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 placed as an object on Facebook, then you can use the action (new_zombie) on the object. I am also in the same situation (with the changes included in July 2013), trying to figure it out in order to create everything in one step on Facebook, but I could not understand it without using a separate stand-alone web server. In my problem, I get an error when the object is already sent and cannot be sent again. If you do not have this problem, you can continue to work with it.

It seems that the error itself is caused by the fbsdk:create_object (and its value 1 ) in the object dictionary. This key is automatically added to the Facebook SDK in the asset. When I deleted this key explicitly before publishing, it did not throw an exception in the mail, but my answer about publishing the object still applies. Even if you delete this key, you will get an OAuthException on the server side, indicating that the object is not a "link". I would be very happy if I were mistaken in this.

0
source

I just added these lines before calling the API and it works great!

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

This seems to be a bug in the Facebook SDK! he is trying to encode a boolean

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); }]; } 
0
source

Source: https://habr.com/ru/post/1492590/


All Articles