如何刷新Spotify令牌

时间:2019-03-16 14:35:44

标签: php api spotify

由于Spotify的令牌在一小时内到期,因此我正在寻找一种获取新令牌的方法。

以下代码无法做到。

有人可以发现我的代码有问题吗?

<?php
function get_token(){
    $url = "https://accounts.spotify.com/api/token";
    $fieldString = "";
    $ClientID     = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $ClientSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
    $headers = array(
        "Accept: application/json",
        "Content-Type: application/x-www-form-urlencoded",
        "Authorization: Basic ".base64_encode($ClientID.":".$ClientSecret)
    );
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    $response = curl_exec($ch);
    $json = json_decode($response);
    curl_close($ch);
    return $json->access_token;
}

get_token();

0 个答案:

没有答案