Oleg Dats
Oleg Dats

Reputation: 4133

How to get all people who liked Facebook post?

I have FB post
I can click "77 people like this" and get all people I needed.
Question: is there way to get these people by FB API ?
PS I want to get 3 random names from these list so I need to have these people in JSON format

Upvotes: 0

Views: 4681

Answers (2)

Random Integer
Random Integer

Reputation: 106

I'm one of the co-founders of Kither, a platform for checking all of your Facebook stats. We have added many features which requires to fetch all of our user's posts likes.

As of August 6, 2016, FQL is deprecated.

Facebook's Graph API's still available and you can call https://graph.facebook.com/{api-version}/{post-id}/likes to get likes on posts. But remember, Facebook uses pagination on likes if there are more than 1,000 of them.

Now, In this case you'll need to call the next page url.

Facebook Likes' pagination

You'll need to call the next url unless you've got all the likes. (you won't find any next field if there are no more likes)

To get how many people have liked that post (i.e. count), you don't need to page through results. You can simply use https://graph.facebook.com/{api-version}/{post-id}/likes?summary=true and you'll get an extra field containing all likes' summary, including their count.

Same can be done with comments and recently added, reactions.

Upvotes: 0

cpilko
cpilko

Reputation: 11852

It's easy to do with FQL. This gets you three random ids of people who liked this event

SELECT user_id FROM like WHERE object_id = 336638873112346 ORDER BY rand() LIMIT 3

If you wanted to get their names instead, you'd rewrite the query like this:

SELECT uid, name, username FROM user WHERE uid IN 
 (SELECT user_id FROM like WHERE object_id = 336638873112346 ORDER BY rand() LIMIT 3)

Upvotes: 2

Related Questions