Tero

[+] Get Facebook Fan Page Count

Nov 2nd, 2016
776
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.28 KB | None | 0 0
  1. <?php
  2. /**
  3. + Info: How to Use New Facebook API 2.8 for Fan Page
  4. + Pastebin: http://pastebin.com/u/tero
  5. **/
  6.  
  7. # The PHP Code
  8. function fb_count($pageid) {
  9.  
  10. $fb_vs  = 'v2.8'; // The most recent version of the API
  11. // Important: You must have App ID and App Secret for this code to work.
  12. // You have to replace these settings, they will not be available for long time.
  13. $appid  = '259036654457513';
  14. $secret = '032ce70371267b1e80691ea0f59eb12c';
  15.  
  16. $fb_url = "https://graph.facebook.com/".$fb_vs."/".$pageid."?fields=fan_count&access_token=".$appid."|".$secret;
  17.  
  18.     if (!empty($pageid)) {
  19. $decode = json_decode(@file_get_contents($fb_url));
  20.  
  21.    if (empty($decode->id))
  22.     $result = 'This facebook page id doesn\'t exist.'; // If the page doesn't exist or access token is not set.
  23.    else
  24.     $result = $decode->fan_count; // Here is the correct result
  25.     }
  26.    else {
  27.     $result = 'You need to provide a facebook page !'; // When is not set anything
  28.      }
  29. return $result;
  30. }
  31.  
  32. # How to use
  33. /*
  34.    You can use three options (Example):
  35.    URL: http://facebook.com/eutub
  36.    Page ID : 289156601188161
  37.    Page Username: Eutub
  38. */
  39. $fanpage = 'eutub';
  40. echo fb_count($fanpage); // result: 116093 likes.
  41. // This will return the number of fan in your Facebook page.
  42. ?>
Advertisement
Add Comment
Please, Sign In to add comment