在 Google 脚本中:UrlFetchApp.fetch(https://accounts.spotify.com/api/token) 返回代码 405



在谷歌脚本中,我试图从spotify调用client_credentials OAuth流,虽然它应该返回访问令牌,但请求失败,代码为405。

data = {
    'grant_type':'client_credentials',
    'client_id' : 'CLIENT_ID',
    'client_secret' : 'CLIENT_SECRET'
}
var access_token= UrlFetchApp.fetch('https://accounts.spotify.com/api/token', data);

更多关于 Spotify OAUTHhttps://developer.spotify.com/web-api/authorization-guide/#client-credentials-flow

您的请求格式不正确。如果仔细查看文档,您会发现只有grant_type应作为请求正文参数发送。

客户端 ID 和密钥应作为标头参数发送。参数名称应为授权,参数值应为基本 [base_64_encoded_value_of(client_id:client_secret(]

最新更新