Jump to content

Undefined index: access_token


hackalive

Recommended Posts

Hi guys,

 

I have and am using this code:

	$postQuery = array('grant_type'=>'authorization_code',
						'client_id'=> $app_id,
						'client_secret'=> $app_secret,
						'code'=> $_REQUEST['code'],
						'redirect_uri'=> $my_url);

	$ch = curl_init();

	curl_setopt($ch, CURLOPT_URL, 'http://localhost/token.php');
	curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1");
	curl_setopt($ch, CURLOPT_HEADER, false);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($ch, CURLOPT_POST, true);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $postQuery);
	curl_setopt($ch, CURLOPT_TIMEOUT, 10);
	$output = curl_exec($ch);
	curl_close($ch);

	$params = null;

	parse_str($output, $params);

	$api_url = "http://localhost/?access_token=" . $params['access_token'];

 

Now token.php returns:

{"access_token":"24379238d539a2874069c6602e235bd7b6c3c0d3","expires_in":3600,"token_type":"bearer","scope":"","refresh_token":"e9de4c94038e135b0592bc0886b1b4d5a14e6105"}

 

However the PHP script (mostly the part below)

	$params = null;
	parse_str($output, $params);
	$api_url = "http://localhost/?access_token=" . $params['access_token'];

 

is returning:

Notice: Undefined index: access_token in \public\app.php on line 47

 

How can I resolve this?

 

Many thanks in advance :)

Link to comment
https://forums.phpfreaks.com/topic/260505-undefined-index-access_token/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.