Extract token from response url - Spotify API Extract token from response url - Spotify API curl curl

Extract token from response url - Spotify API


You need to decode the JSON:

$response = json_decode($response, true);

Then you'll have an array with the values.

$token = $response['access_token'];

Also, you're missing a necessary option to obtain the response in this way:

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

If not defined, you will get a boolean value instead of the response.


curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

use this line too before your curl execute then it gives you proper json