且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spotify API授权+令牌密钥错误-Python3

更新时间:2022-01-28 07:34:24

之所以起作用,而不是现在起作用,是由于access token到期.

The reason why it worked before and not now is due to the expiration of the access token.

令牌的到期时间由Spotify确定,因此您只需要解决它们的设置约束.

The token's expiration time is determined by Spotify so you just have to work around their set constraints.

话虽如此,您可以根据请求请求令牌(https://accounts.spotify.com/api/token)时Spotify在响应中发回的属性expires_in来预测何时需要生成/使用新令牌. expires_in属性是一个整数,它告诉您令牌将使用多少秒.如其授权文档所示, expires_in属性的返回值为3600(秒)或1小时.

That being said, you can anticipate when a new token will need to be generated/used based on the property expires_in which Spotify sends back in the response when you request a token (https://accounts.spotify.com/api/token). The expires_in property is an integer and it tells you how many seconds the token will be good for. As seen in their authorization documentation, the expires_in property is returned with the value 3600 (seconds) or, 1 hour.

该小时结束后,使用您的refresh_token请求新令牌.

After that hour is up, use your refresh_token to request a new token.