10

How do you post a "like" with the Facebook Graph API?

Christoffer
  • 25,035
  • 18
  • 53
  • 77
  • 1
    duplicate 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 Answers8

17

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.

Igy
  • 43,710
  • 8
  • 89
  • 115
Peter Bailey
  • 105,256
  • 31
  • 182
  • 206
  • 2
    Ok, 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
  • 1
    How 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
  • 11
    I 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
9

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.

serg
  • 109,619
  • 77
  • 317
  • 330
2

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.

Christian Specht
  • 35,843
  • 15
  • 128
  • 182
SundialSoft
  • 136
  • 8
1

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

Oyeme
  • 11,088
  • 4
  • 42
  • 65
1

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>
sakibmoon
  • 2,026
  • 3
  • 22
  • 32
Edd Turtle
  • 1,511
  • 1
  • 13
  • 24
0

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.

user331244
  • 601
  • 9
  • 19
0

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

iddo
  • 182
  • 6
0

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.