13

Is there a way to retrieve the list of Facebook users that have clicked the like button on an external website?

  • E.g. there is a domain example.com which has been confirmed via Facebook Insights to belong to fbUser1 (using OG meta tags).
  • Somewhere on example.com there is a page with multiple XFBL like buttons, each one pointing to a further specific URL on example.com, e.g. example.com/xyz, example.com/abc etc.

What I'd like to get is the list of users that liked example.com/xyz and of those who liked example.com/abc.

My intuitive approach would be to look at graph.facebook.com/123456789/likes (where the number is the ID of the domain taken from FB insights), but this always returns an empty dataset:

{
   "data": [

   ]
}

I've also tried getting an OAuth access token from https://graph.facebook.com/oauth/access_token?type=client_cred&client_id=APPID&client_secret=APPSECRET (where APPID and APPSECRET are taken from a FB application that is marked as owning the domain using OG meta tags), but that makes no difference.

I'd also be interested in a non-OpenGraph (i.e. JS SDK, FQL etc.) solution.

EDIT: Using the following code (according to WideBlade's answer below) still gives me an empty list of likes (the second query never returns):

var objectsQuery = "select id from object_url where url in ('http://example.com/xyz', 'http://example.com/abc', 'http://example.com/123')";
var likesQuery = "select object_id from like where object_id = {0}";

FB.Data.query(objectsQuery).wait(function (objectRows) {
    console.log(objectRows);

    FB.Array.forEach(objectRows, function (objectRow) {
        FB.Data.query(likesQuery, objectRow.object_id).wait(function (likeRows) {
            console.log(likeRows);
        })
    });
});
Community
  • 1
  • 1
Samu Lang
  • 2,261
  • 2
  • 16
  • 32

2 Answers2

5

FQL Should do the trick.

$facebook->api_client->fql_query('SELECT user_id FROM like WHERE object_id="OBJECTID"');

Here is the link.

Some general info about FQL.

FQL is initiated using the JavaScript SDK, in this way.

If you can post some sample code-I can try and give some more specific help.

A note should be made-once you've got the user ID's, you can just query the names and get them in a list.

EDIT: To get the URL of an object you should query this table using fql.

Tom Granot
  • 1,840
  • 4
  • 22
  • 52
  • Lovely, thanks. How do I get an OBJECTID for an external url like example.com/xyz? – Samu Lang Feb 03 '11 at 09:38
  • Thanks again, accepted as obviously correct. However using JS SDK and FQL the list of likes is still empty. See edit for sample. – Samu Lang Feb 03 '11 at 11:50
  • Thanks, but I don't think this is a JS problem. The code works fine, and the results are the same as when querying the OpenGraph or even the old REST API. The question is really: is there a way to retrieve the specific users who like an external url? – Samu Lang Feb 03 '11 at 12:55
2

This cannot be done. Facebook does not allow you to query for specific user ID's of people who have liked a certain page. This is because of privacy concerns.

See the disclaimer on this page https://developers.facebook.com/docs/reference/fql/like/

sid
  • 44
  • 1