2017-06-16 96 views
0

在Google脚本中,我试图从spotify调用client_credentials OAuth流,而它应该返回访问令牌,请求失败,代码405在Google脚本中:UrlFetchApp.fetch(''https://accounts.spotify.com/api/token'')返回代码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

回答

0

您的请求的格式不正确。如果你仔细看看the documentation,你会发现只有grant_type应该作为请求主体参数发送。

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