1

I'd like to know if a user already liked a specified element, i.e. a Wordpress article before. I know how to capture like events using FB.Event.subscribe('edge.create', handler);, but I could not find a similar method to check the current status (when loading a page). I guess there should be a Graph API query to resolve this, but I could not find it...

Cedric Reichenbach
  • 8,970
  • 6
  • 54
  • 89

1 Answers1

2

This is the thing that you are looking for

http://developers.facebook.com/docs/reference/api/post/

I think it would be better if you just used fql.You would need a query wihich is something like this

SELECT user_id FROM like WHERE post_id="THE ID OF YOUR POST"

with this you have all the ids of all the users who have liked your post.Once you have a collection you can just filter it for the user that you are looking for.

You can find more info here

http://developers.facebook.com/docs/reference/fql/like/

Edit to get like for any element:

The above query would work for any element

for ex if you want to get likes for any image

SELECT user_id FROM like WHERE object_id="The object_id of a video, note, link, photo"

Now there are some complications to this you would have to first find out what the id of the link is.You can do that using the links table in the fql.

Akshat Jiwan Sharma
  • 15,430
  • 13
  • 50
  • 60
  • Oh, I guess I was no clear enough: By post, I don't mean a facebook post, but just any element, in this case a post on a wordpress site... – Cedric Reichenbach Oct 07 '12 at 16:37
  • 1
    The post on the wordrpress site will be treated like a link and in that case you can use object_id instead of post_id.See the links for reference.Let me know if it is not working for you.Though I am certain that it would. – Akshat Jiwan Sharma Oct 07 '12 at 16:44
  • Yes, this seems to be what I'm searching for! Anyway, I'm still confused by facebook's API/FQL documentation... How do I fire such queries, should I use AJAX by hand or is there some API method? And how do I get the object_id from an url? Sorry for all this questioning... – Cedric Reichenbach Oct 07 '12 at 16:51
  • No problem :). it is very confusing.I suggest that you take it one step at a time.Go to this page http://developers.facebook.com/tools/explorer/?method=GET&path=2439131959 and hit the fql tab.practice your queries there for which you know the result.As for how to use the query with java script sdk check out this question http://stackoverflow.com/questions/10997805/using-facebook-javascript-sdk-to-proceed-fql-query.One thing that I would like to add is that make sure that all your api calls have a valid access token since they seem to expire quickly. – Akshat Jiwan Sharma Oct 07 '12 at 16:58
  • So I managed to fire queries and get the object_id. But when I use your query to receive ids of liking users, an empty array is returned. But this should not be possible, because I liked it with my own account for testing... And the token seems to be valid, otherwise, I would get an error message in the returned query, right? – Cedric Reichenbach Oct 07 '12 at 17:33
  • I was working on localhost, and wouldn't like to upload it until it's working... Beside the button, it says "1" too, so there must be another problem... I also checked it here, is this query correct? https://developers.facebook.com/tools/explorer/?fql=SELECT%20user_id%20FROM%20like%20WHERE%20object_id%3D%2210150942842578475%22 – Cedric Reichenbach Oct 07 '12 at 17:44
  • looks okay to me.One thing and it is just a guess have you authorized your app to get read permissions to query user_id?to quote from the facebook page on likes "To read the likes table you need any valid access_token if it is public (visible to anyone on Facebook). any valid access_token for the current session user if it is not public and is visible to the user. read_stream permissions to query user_id as an indexable field." the third point is what I am talking about. – Akshat Jiwan Sharma Oct 07 '12 at 17:57
  • Yeah, I just read that it's not possible to receive liking user ids from an object_id, only vice versa. But I guess it's not easily possible to get the current user's user_id... – Cedric Reichenbach Oct 07 '12 at 18:00
  • I tired this query and it works SELECT user_id FROM like WHERE object_id="10151113094863271" – Akshat Jiwan Sharma Oct 07 '12 at 18:10
  • There can be one of two things either the object id is wrong or you do not have read permissions enabled. – Akshat Jiwan Sharma Oct 07 '12 at 18:11
  • It's working for me too, but this is a profile, mine an object... I'm not sure what's going on, I'll check that later. Thanks for now... – Cedric Reichenbach Oct 07 '12 at 18:27