I'm an amateur programmer trying to fetch my facebook page likes for my webpage since I do not want facebooks standard plugin. After a lot of research and testing I found out the right call to make which is:
https://graph.facebook.com/{PAGE_ID}?access_token={APP_ID}|{APP_SECRET}&fields=fan_count
Using this in my web browser it works great and I get the fan count in json.
My problem is when I try to make this call using either cURL or file_get_contents inside a php script I dont seem to get anything back. After doing a var_dump I get bool(false) back. And after doing print_r I get nothing.
Is facebook somehow blocking my calls or what could be wrong? I have tried multiple ways I found online and none works. This is one of the examples:
<?php
$json_url = "https://graph.facebook.com/XXXXXXXXXXX?access_token=XXXXXXXXXXXXX&fields=fan_count";
$json = file_get_contents($json_url);
$json = json_decode($json, true);
print_r($json);
echo "Number of likes : ". $json[0]->fan_count;
?>
This is another:
<?php
$ch = curl_init("https://graph.facebook.com/v2.6/XXXXXXXXXXXXX?access_token=XXXXXXXXXXXX&fields=fan_count");
curl_setopt( $ch, CURLOPT_POST, false );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt( $ch, CURLOPT_HEADER, false );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$data = curl_exec( $ch );
echo $data;
?>
The problem seem to be right after the graph call. Can't figure out why, all help will be appreciated :) Thanks!