以下是 Spotify API 的文档(我使用的是隐式授权流程):https://beta.developer.spotify.com/documentation/general/guides/authorization-guide/#implicit-grant-flow https://beta.developer.spotify.com/documentation/general/guides/authorization-guide/#implicit-grant-flow
我正在尝试在 Google 表格中编写脚本。我专注于基本设置,但我似乎无法使访问令牌正常工作。
SOLVED:
我目前收到以下错误(这似乎是我的
我的获取方法的参数设置不正确):
“error”:“unsupported_grant_type”,“error_description”:“grant_type必须是client_credentials、authorization_code或refresh_token”
解决方案:
根据 Google 的规定,grant_type 必须列为有效负载
脚本方法 UrlFetchApp.fetch(请参阅下面更新的代码)
--
SOLVED:
正如您在下面看到的,我在尝试获取时使用“get”方法
令牌(尽管文档指定了“post”),因为该帖子
方法始终返回 405 错误。我想这就是我要迈出的一步
搞砸了。我假设我不应该使用
csrf_token 作为访问令牌。
解决方案:
https://accounts.spotify.com/token https://accounts.spotify.com/token本来应该https://accounts.spotify.com/api/token https://accounts.spotify.com/api/token
更新后的工作代码如下:
var fetchParams = {
'method':'post',
'payload':{'grant_type':'client_credentials'},
'headers':{'Authorization':authorization},
'muteHttpExceptions':true
}
var replaceResponse = UrlFetchApp.fetch('https://accounts.spotify.com/api/token', fetchParams);
var regExp = /access_token(.*?):/;
var contentText = replaceResponse.getContentText();
var access_token = contentText.slice(contentText.search('access_token')+15,contentText.search(',')-1);
var requestOptions = {
'headers':{'Authorization':'Bearer '+access_token},
'muteHttpExceptions':true
}
var finalResponse = UrlFetchApp.fetch('https://api.spotify.com/v1/tracks/4dhARBZ8YLvm8oRDnCIeXr', requestOptions);