I’m trying to request the access token from the spotify API, I made it thru the first part with logging in, but I cant figure out the correct curl.
This is my code
$auth_token = $_GET['code'];
$clientSecret = '11111111111';
$url = 'https://accounts.spotify.com/api/token';
$clientID = '22222222222';
$redirect_uri = 'https://www.mydomain.com/test/spotify';
$oauthFields = array(
'client_id' => $clientID,
'client_secret' => $clientSecret,
'grant_type' => 'authorization_code',
'code' => $auth_token,
'redirect_uri' => $redirect_uri);
$parameters = http_build_query($oauthFields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$parameters);
curl_setopt($ch, CURLOPT_POST, count($oauthFields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
$urlResponse = curl_exec($ch);
curl_close($ch);
$spotify = json_decode($urlResponse);
https://developer.spotify.com/documentation/general/guides/authorization-guide/