D
D
dmitrypix2016-08-23 11:35:34
Facebook
dmitrypix, 2016-08-23 11:35:34

Displaying the number of followers of a Facebook page?

Tell me, before the output of the number of subscribers worked like this

<?php echo get_facebook_page_likes('id page');?>

function get_facebook_page_likes($page_id, $echo=false){
  $xml = @simplexml_load_file("http://api.facebook.com/restserver.php?method=facebook.fql.query&query=SELECT%20fan_count%20FROM%20page%20WHERE%20page_id=".$page_id."") or die ("много");
  $likes = $xml->page->fan_count;
  if($echo == true){
    echo $likes;
  } else {
    return $likes;
  }
}

What is not working now. What needs to be changed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Finesse, 2016-08-25
@dmitrypix

Try the current API:

echo get_facebook_page_likes('page id');

function get_facebook_page_likes($page_id) {
    $url = 'https://graph.facebook.com/v2.11/'.urlencode($page_id).'?fields=fan_count&access_token=ТОКЕН';
    $data = json_decode(file_get_contents($url));
    return $data->fan_count;
}

How to get ТОКЕН:
  1. Create an app on Facebook.
  2. TOKEN = AppID|AppSecret, where AppID is the identifier of the created application, AppSecret is the application's secret key.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question