iOS how to publish action on custom object Graph Api - Facebook
Asked Answered
C

1

6

I need to publish action

I got success in publishing 'liking the link' from graph API. e.g 'abc likes www.abc.com'

now I am stuck at 'liking custom object' e.g 'abc likes toy1' and also to get total number of likes.

This is sample code which is not working

       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 is working by changing

toy

to

appnamespace:toy

and

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

now I want to fetch total number of likes on this custom object

Chicle answered 6/5, 2015 at 9:0 Comment(0)
J
0

A "og:type" of "toy" is not valid. It should either be a common OG type (like "fitness.course") or a custom one ("yourappnamespace:toy").

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

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

(note that if you try to like the same thing twice it will give you an error).

You should make sure your delegate implements - (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error to receive error information.

You may also want to use the FBSDKLikeButton or FBSDKLikeControl instead.

Jackleg answered 6/5, 2015 at 22:4 Comment(2)
Thank you Chris for answer, now its giving error like "value for toy is required"Chicle
can you file a report to developers.facebook.com/bugs so we can get more information like your app id?Jackleg

© 2022 - 2024 — McMap. All rights reserved.