Как обновить токен Spotify - PullRequest
0 голосов
/ 16 марта 2019

Поскольку срок действия токена 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();
...