EDIT
Please note, my issue is with regard to the url not returning any data at all....not about the API version as mentioned and answered in the 'duplicate' question' and as occurs later in my code. That could be another question.
So please, I need votes to reopen this question !
Original Question
Hi there are a few questions on SO on this. But none specifically or generically addresses my issue. So here i am.
I am trying to create a facebook page/group post script in PHP. The specific part of code I am mentioning here relates to a larger code that is supposed to list the pages of the facebook account and create a dropdown so the required page to be posted to can be selected.
I have the API set up. I have the SDK. I have the codes.
The issue is, when I execute the code to get the access toke vide Curl (file_get_contents returns permission denied error), I get a blank in the response.
The code is as follows;
$token_url = "https://graph.facebook.com/oauth/access_token?"
. "client_id=".$config['appId']."&redirect_uri=" . urlencode($config['callback_url'])
. "&client_secret=".$config['secret']."&code=" . $_GET['code'];
echo $token_url."<br>";
// $response = file_get_contents($token_url); // get access token from url
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $token_url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
curl_close ($ch);
echo "RESPONSE :".print_r($response);
$params = null;
parse_str($response, $params);
$_SESSION['token'] = $params['access_token'];
// echo "<script>alert(SESSION TOKEN : $_SESSION[token])</script>":
echo "SESSION TOKEN : ".$_SESSION['token']."<br>";
echoing $response and Print_r gives a blank.
The response on screen is
RESPONSE :
Notice: Undefined index: access_token in /home/u154857672/public_html/admin/fb/getlist.php on line 35
SESSION TOKEN :
Notice: Trying to get property of non-object in /home/u154857672/public_html/admin/fb/getlist.php on line 77
Where am I going wrong ? What other info is required to elaborate the problem ?