IOS how to post action on Graph Api custom object - Facebook

I need to post an action

I have been successful in posting the like link from the graphical API. for example, 'abc loves www.abc.com'

now I am stuck in a β€œnice user object”, for example, β€œabc loves a toy1” and also get the total number of likes.

This is an example of code that does not work.

NSDictionary *properties = @{ @"og:type": @"toy", @"og:title": @"toy1", @"og:description": @"This is a sample course."}; FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties]; FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init]; action.actionType = @"og.likes"; [action setObject:object forKey:@"toy"]; FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init]; content.action = action; content.previewPropertyName = @"toy"; FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init]; // optionally set the delegate shareAPI.delegate = self; shareAPI.shareContent = content; [shareAPI share]; 

Edit: my code works by modifying

 toy 

to

 appnamespace:toy 

and

 [action setObject:object forKey:@"toy"]; // to [action setObject:object forKey:@"object"]; 

now I want to get the total number of likes on this user object

+6
source share
1 answer

"og: type" from "toy" is not valid. It must be either a generic OG type (for example, "fitness.course") or regular ("yourappnamespace: toy").

If you just like a website or other URL, you can skip the OG object and just create an action like

  FBSDKShareOpenGraphAction * action = [FBSDKShareOpenGraphAction actionWithType: @ "og.likes"
                                                                     objectURL: [NSURL URLWithString: @ "http://www.example.com"]
                                                                           key: @ "og: object"];

(note that if you try to repeat the same thing twice, this will give you an error).

You must ensure that your delegate implements - (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error to get - (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error information.

Instead, you can use FBSDKLikeButton or FBSDKLikeControl .

0
source

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


All Articles