İlk Spotify uygulaımı yapıyorum ve şu anda yetkilendirme süreciyle uğraşıyorum.Spotify API - yetkilendirme işlemi sırasında erişim belirteci alınırken hata oluştu
Şimdiye kadar https://accounts.spotify.com/authorize
benim Devleti ve kod almak ve şimdi benim erişim belirteci elde etmek PHP CURL istek üzerinden bir POST isteği yolluyorum başarılı olmuştur.
Spotify's instructions for this step
benim grant_type geçerli olmadığını belirten aşağıdaki JSON hata yanıtını almaya devam ve üç geçerli seçenekler beni sunmaktadır:
{ "hata": "unsupported_grant_type", "ERROR_DESCRIPTION":" grant_type client_credentials, authorization_code veya refresh_token olmalıdır "} bool (true)
Aşağıdaki koduma bakarsanız," authorization_code "ifadesinin doğru grant_type değerini ayarladığımı, ancak hatayı alıyorum. Doğru kod satırı olduğuna inandığım şeyin kod snippet'ini '******' ile vurguladım.
Yanlış yaptığım şeyi herkes görebilir mi? İşte isteği göndermek için kullanıyorum kodu:
// Get access tokens
$ch = curl_init();
// Specify the HTTP headers to send.
//Authorization: Basic <base64 encoded client_id:client_secret>
$ClientIDSpotify = "[my spotify app id]";
$ClientSecretSpotify = "[my secret code]";
$authorization = base64_encode ("{$ClientIDSpotify}:{$ClientSecretSpotify}");
$http_headers = array(
"Authorization: Basic {$authorization}"
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers);
curl_setopt($ch, CURLOPT_POST, true);
$spotify_url = "https://accounts.spotify.com/api/token";
curl_setopt($ch, CURLOPT_URL, $spotify_url);
// *************************************************
// HERE'S WHERE I CORRECTLY SPECIFY THE GRANT TYPE
// *************************************************
$data['grant_type'] = "authorization_code";
$data['code'] = $authorizationCode;
$callbackURL = "[my callback URL]";
$data['redirect_uri'] = $callbackURL;
curl_setopt($ch, CURLOPT_SAFE_UPLOAD, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response_json = curl_exec($ch);
curl_close($ch);
}
Teşekkürler, Michael, bunun bir şeyleri değiştirip değiştirmediğini göreceğim. – Tobraham
Hayır, aynı hata. – Tobraham
Soruya json_encode ($ data) çıktısını ekleyebilir misiniz? –