www.webdeveloper.com
Results 1 to 4 of 4

Thread: Can't count Facebook shares

  1. #1
    Join Date
    Sep 2007
    Posts
    13

    Unhappy Can't count Facebook shares

    Hi,

    I'm trying to count the Facebook shares a webpage has through the Facebook API. When I do it in my computer with wamp (PHP version 5.3.8), I get the results right, but when I do it in the server that I'm paying (PHP version 5.2.17), the variables are empty. I don't know if it's because of the PHP version or if my provider can change some parameters to make it work. The codes I'm using are:

    Code:
    function get_likes($url) {
      $json_string = file_get_contents('http://graph.facebook.com/?ids=' . $url);
      $json = json_decode($json_string, true);
      return intval( $json[$url]['shares'] );
    }
    
    $likes = get_likes("http://www.flightpodcast.com/episode-6-john-bartels-qantas-qf30");
    echo "likes = $likes";
    and
    Code:
    $source_url = "http://www.flightpodcast.com/episode-6-john-bartels-qantas-qf30";
    $url = "http://api.facebook.com/restserver.php?method=links.getStats&urls=".urlencode($source_url);
    $xml = file_get_contents($url);
    $xml = simplexml_load_string($xml);
    
    echo "Share --- ".$shares = $xml->link_stat->share_count;
    echo "<br/>";
    
    echo "Like --- ".$likes = $xml->link_stat->like_count;
    echo "<br/>";
    
    echo "Comments ---".$comments = $xml->link_stat->comment_count; 
    echo "<br/>";
    
    echo "Total --- ".$total = $xml->link_stat->total_count;
    echo "<br/>";
    
    echo $max = max($shares,$likes,$comments);
    The results are the same.

    Thank you.

  2. #2
    Join Date
    Sep 2007
    Posts
    13
    Here i have the php specifications of the server: http://www.juarjuar.com/pruebas/likecount.php

  3. #3
    Join Date
    Jun 2008
    Location
    Europe
    Posts
    1,097
    Your second code works fine for me on Godaddy:
    http://delpercio.com/fblikes.php

  4. #4
    Join Date
    Sep 2007
    Posts
    13
    I think I found the reason of the problem: the server doesn't allow file_get_contents(URL), which the script needs

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles