Spotify请求令牌返回invalid_client

时间:2017-09-10 11:00:27

标签: php api http-post authorization spotify

我希望有人能在这里帮助我:

我有一个应该使用Spotify API的应用程序。但在请求授权本身后,我被困在请求令牌。相关代码如下:

function post($content, $url,$clientId,$clientSecret)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
curl_setopt($ch, CURLOPT_HTTPHEADER,
    array(
        'Content-Type: application/x-www-form-urlencoded',
        'Authorization: Basic '.base64_encode($clientId).':'.base64_encode($clientSecret)));
return curl_exec($ch);
}
$clientId="4df42e27a76d41f9961b0952102fexxx";
$clientSecret="3088a8b6132b40dc980540880cf5bxxx";
$content=array(
'grant_type' => 'authorization_code',
'code' => $_GET["code"],
'redirect_uri' => 'http%3A%2F%2Fhome.xxx.de%2Ftoken.php',
);
echo post($content,"https://accounts.spotify.com/api/token",$clientId,$clientSecret);

不幸的是,结果是{“error”:“invalid_client”},我不明白为什么......

1 个答案:

答案 0 :(得分:0)

  

授权

     

必需。

     

Base 64编码的字符串,包含客户端ID和客户端密钥。该字段必须具有以下格式:

  Authorization: Basic <base64 encoded client_id:client_secret>

我将其视为base64_encode($clientId.':'.$clientSecret)

相关问题