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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.