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

时间:2017-06-16 20:06:36

标签: javascript spotify libspotify

在Google脚本中,我尝试从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 OAUTH的信息 https://developer.spotify.com/web-api/authorization-guide/#client-credentials-flow

1 个答案:

答案 0 :(得分:0)

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

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