【发布时间】:2017-10-24 06:16:17
【问题描述】:
我正在尝试使用 Google Apps 脚本向 Spotify API 发出 PUT 和 DELETE 请求。但是,当我这样做时,我收到错误:'405 Not Allowed'。
我真的很困惑为什么这是因为我能够对同一资源发出正确的 GET 请求,而且我也能够在 Paw 和 Postman 等程序中很好地执行这些 PUT 和 DELETE 请求,但是当我在 Google Apps 脚本中执行此操作我收到 405 错误。这是我当前的代码:
var authorisation = "Bearer "+accessToken;
var getUrl = baseURL+'v1/users/'+user+'/playlists/'+playlist+'/tracks';
var replaceOptions = {
"method":"put",
"contentType":"application/json",
"payload":JSON.stringify({"uris": ["spotify:track:4UaGt8uW0srvzFZAwKCumD","spotify:track:5QmvryaxUQyXyFMljdgOPD","spotify:track:5NFNxnghrwogF3H6Pj66f6"]}),
"headers":{"Authorization":authorisation},
'muteHttpExceptions':true
};
var replaceResponse = UrlFetchApp.fetch(getUrl, replaceOptions);
Logger.log(replaceResponse.getAllHeaders());
Logger.log(replaceResponse.getContentText());
Logger.log(replaceResponse.getResponseCode());
对于正在发生的事情,我真的很感激。仅供参考,这是原始端点文档here。
【问题讨论】:
-
您是否尝试删除您的 JSON.Stringify 以将 json 直接保留在您的有效负载中?
-
是的,我什至从邮递员那里复制并粘贴了工作 json 字符串到有效负载中
标签: javascript google-apps-script spotify