开发者

Post a "Like" with the Facebook Graph API?

How do you p开发者_如何学Pythonost a "like" with the Facebook Graph API?


With the Graph API itself, you can't.

The Graph API can Like some objects (posts, pictures, etc), but not top-level items like Pages and URLs; the only way for those items to be liked is via the Like button or Facebook's own interfaces.


You can like a wall post:

You can comment on or like a post by posting to https://graph.facebook.com/POST_ID/comments and https://graph.facebook.com/POST_ID/likes, respectively:

curl -F 'access_token=...' \
     https://graph.facebook.com/313449204401/likes

see Publishing to Facebook. If you need to like a webpage - probably not.


While adding to the facebook content in my first app I found it hard to find reliable info on how to like a post or comment on a post.

The graph api commands /likes and /comments used on their own return a set of data with the info on who likes or commented on a post BUT the same commands also post a like or a comment against the posting if you add an NSMutableDictionary into the call to the graph api as params.

So with a /likes which does not actually need any params content I just used the same dictionary as comments without the actual message eg:

NSString *graphPath = [NSString stringWithFormat:@"%@/likes" ,postId];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"", @"message", nil];    
[appDelegate.facebook requestWithGraphPath:graphPath andParams:params andHttpMethod:@"POST" andDelegate:self];

You will have already obtained the post id when you obtained the newsfeed. This works fine so long as your app has the normal permission to post. There are lots of confusing posts about likes out there. Hopefully this is not one of them.

nb: If you have not downloaded the facebook connect stuff from github recently you should do so as it's been updated.


http://developers.facebook.com/docs/reference/plugins/like see here :)


You can use an iframe or the Javascript SDK. The code for an iframe like button is as follows:

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fexample.com%2Fpage%2Fto%2Flike&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>


Use POST on

https://graph.facebook.comme/likes?url=http%3a%2f%2fstackoverflow.com%2f&message=Yes%2c+we+can

and a like is created.


It seems the open-graph api has now been updated to support creating likes: https://developers.facebook.com/docs/opengraph/actions/builtin/likes/


Note: as of Nov 17, 2016 we changed the behavior of publishing likes and only support this action with Page Access Tokens. This means you can publish likes onbehave of pages only and this is worthless.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜