How do you post a "like" with the Facebook Graph API?
-
1duplicate of http://stackoverflow.com/questions/3692527/how-to-programmatically-press-a-like-button-through-a-facebook-application – Denis Sep 14 '10 at 19:31
8 Answers
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.

- 43,710
- 8
- 89
- 115

- 105,256
- 31
- 182
- 206
-
2Ok, I'll bite. Why the hit & run downvote on a year-old question? It's true that since this post was make they've added the ability to generate Likes for various FB objects, but you still can't generate a Like for other objects in the Open Graph. – Peter Bailey Sep 22 '11 at 16:50
-
Possibly because you didn't actually site any kind of reference. Why should I trust that you can't, simply because you say so? – user229044 Sep 28 '11 at 19:05
-
1How do you prove something's non-existence? Should I link to a page of documentation that doesn't exist? Might as well ask me to provide a reference as to why you can't post to FB with colored text. – Peter Bailey Sep 28 '11 at 19:25
-
A little bit of reasoning then, *something* to justify your answer. "You can't" is never a *good* answer for Stack Overflow. Just because *you* don't know how to do something, doesn't mean it can't be done, and that's what your answer looks like: *You* don't think it's possible. – user229044 Sep 28 '11 at 20:53
-
11I guess 30k rep and facebook badge buys you no credibility =/ How's this for reasoning: you can't because the API doesn't have a method for doing so. – Peter Bailey Sep 29 '11 at 21:18
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.

- 109,619
- 77
- 317
- 330
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.

- 35,843
- 15
- 128
- 182

- 136
- 8
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&layout=standard&show_faces=true&width=450&action=like&colorscheme=light&height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>

- 2,026
- 3
- 22
- 32

- 1,511
- 1
- 13
- 24
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.

- 601
- 9
- 19
-
2Your going to get a "(#200) App does not have permission to make this call" – George Marshall May 23 '12 at 19:41
It seems the open-graph api has now been updated to support creating likes: https://developers.facebook.com/docs/opengraph/actions/builtin/likes/

- 182
- 6
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.

- 81
- 8