2017-06-16 95 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)]