当旧的 Spotify 到期时,我可以自动获得新的令牌吗?

Can I get a new token automatically when the old one expires Spotify?

spotify 中的令牌将在 1 小时后过期。一个小时后,您需要粘贴一个新的。有没有一种方法可以自动检索新令牌来代替无效令牌? 有没有办法自动捕获此令牌? 我会将令牌保存在 token 变量中。

return this. $ http.get ("https://api.spotify.com/v1/search", 
    {Header:{'Authorization': `$ {token}`}, params})

有很多方法可以做到这一点。

其中一种方法是捕获来自 API 的拒绝(401 或 403 错误),生成一个新令牌并重新调用第一个 API。

另一种方法是放置一个 setTimeout 以在一个小时后生成一个新令牌。