Search code examples
phpfacebookfacebook-graph-apifacebook-fqlfacebook-graph-api-v2.0

Why is Facebook graph returning 0 likes for this page?


I have been trying to figure out why this request to Facebook API returns 0 likes for this page - https://www.facebook.com/Lilyspad58.

Here is the request:

https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22https://www.facebook.com/Lilyspad58%22

Response:

<fql_query_response xmlns="http://api.facebook.com/1.0/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" list="true">
    <link_stat>
        <like_count>0</like_count>
    </link_stat>
</fql_query_response>

Here's an example where the API returns the number of likes:

https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22https://www.facebook.com/CriaBabyShoes%22

The only difference is the page in the url parameter.

Here is the PHP code I have been using:

function fbLikeCount($url)
{
    //Construct a Facebook URL
    $req = "https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22$url%22";
    $contents = file_get_contents($req);

    print "REQ: $req\n";
    print "Response: $contents\n";
    if ($xml=simplexml_load_string($contents))
    {
        $likes = $xml->link_stat->like_count;
        return($likes);
    }
    return 0;
}

I have tried a range of other Facebook pages in the url parameter, and from what I've been able to determine it that it either works or returns 0. When it returns 0, it always returns 0. When I manually inspect the page in my browser I see the likes.

There is no obvious explanation that I can find in the FB docs, SO or Google.


Solution

  • First of all: FQL is deprecated since years, you really should not try to use it anymore.

    The page is most likely restricted by age or location, so you need a User Token or Page Token to access it. This would be the API call:

    https://graph.facebook.com/Lilyspad58?fields=name,likes

    More information about Access Tokens: