0

I am trying to get a share url count for facebook. Maybe the issue is that the data is aggregated at different times rather than instantaneous however I am getting 0 results for my search.

Here is my code:

<?php
class Sharecount
{
    private $url;
    private $timeout;

    public function __construct($url,$timeout=10)
    {
        $this->url = rawurlencode($url);
        $this->timeout = $timeout;
    }

    public function getFacebookCount()
    {
        $json_string = $this->curlRequest('http://api.facebook.com/restserver.php?method=links.getStats&format=json&urls='.$this->url);
        $json = json_decode($json_string, true);
        return isset($json[0]['total_count'])?intval($json[0]['total_count']):0;
    }

    private function curlRequest($url)
    {
        $ch=curl_init();
        curl_setopt($ch,CURLOPT_URL,$url);
        curl_setopt($ch,CURLOPT_FAILONERROR,1);
        curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
        curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        curl_setopt($ch,CURLOPT_TIMEOUT,$this->timeout);
        $cont=curl_exec($ch);
        if(curl_error($ch)){
            die(curl_error($ch));
        }
        return $cont;
    }
}

Here is my result:

string(264) "[{"url":"http:\/\/url","normalized_url":"http:\/\/url","share_count":0,"like_count":0,"comment_count":0,"total_count":0,"click_count":0,"comments_fbid":null,"commentsbox_count":0}]" 

I'd prefer not to give the URL out so maybe it has to do with the URL

somejkuser
  • 8,856
  • 20
  • 64
  • 130
  • http://stackoverflow.com/questions/5699270/how-to-get-share-counts-using-graph-api – somejkuser Jan 12 '16 at 18:13
  • 1
    That method/endpoint has been deprecated for quite a while now. You should use current API methods for this. https://developers.facebook.com/docs/graph-api/reference/v2.5/url/ – CBroe Jan 13 '16 at 09:13

0 Answers0