hackalive Posted April 7, 2012 Share Posted April 7, 2012 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 More sharing options...
scootstah Posted April 7, 2012 Share Posted April 7, 2012 That is JSON. You'll need to decode it, which will turn it into an object. $json = json_decode($output); $api_url = "http://localhost/?access_token=" . $json->access_token; Link to comment https://forums.phpfreaks.com/topic/260505-undefined-index-access_token/#findComment-1335179 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.