【发布时间】:2016-05-08 17:41:03
【问题描述】:
我一直在为一个项目创建自己的 Spotify API。我遵循了 Web API 教程,但仍然无法获得刷新令牌的授权。
此请求是在我成功获得第一次授权后立即提出的。
谁能发现我的代码有问题?
//Request for refresh token
$url = "https://accounts.spotify.com/api/token";
$fieldString = "";
$fields = array(
"grant_type" => "authorization_code",
"code" => $_GET['code'],
"redirect_uri" => $spotify->getRedirectURI()
//"client_id" => $spotify->getClientID(),
//"client_secret" => $spotify->getClientSecret()
);
$headers = array(
"Accept: application/json",
"Content-Type: application/x-www-form-urlencoded",
"Authorization: Basic ".base64_encode($spotify->getClientID().":".$spotify->getClientSecret())
);
echo http_build_query($fields)."<br/>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
$response = curl_exec($ch);
curl_close($ch);
var_dump(json_decode($response));
【问题讨论】: