php - Facebook Graph API call returns false -
i'm amateur programmer trying fetch facebook page likes webpage since not want facebooks standard plugin. after lot of research , testing found out right call make is:
https://graph.facebook.com/{page_id}?access_token={app_id}|{app_secret}&fields=fan_count
using in web browser works great , fan count in json.
my problem when try make call using either curl or file_get_contents inside php script dont seem back. after doing var_dump bool(false) back. , after doing print_r nothing.
is facebook somehow blocking calls or wrong? have tried multiple ways found online , none works. 1 of 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 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 right after graph call. can't figure out why, appreciated :) thanks!
Comments
Post a Comment