如何为Spotify API编写POST HTTR请求

时间:2016-11-25 20:09:28

标签: r api post spotify httr

我正在尝试通过HTTR和Spotify API在我的Spotify in R中创建一个播放列表。但是,我无法弄清楚如何构造POST请求。

这是我在R中使用的POST请求 HeaderValue = "Authorization Code" n = "application/json" response = POST( 'https://open.spotify.com/v1/users/(myuserid)/playlists', accept_json(), add_headers(Authorization = HeaderValue, "Content-Type" = n), body = list(name = "New Playlist1", public = "true"), encode = 'form', verbose() ) 这是Spotify API网站上的请求应该是这样的: POST /v1/users/121616946/playlists HTTP/1.1 Host: api.spotify.com Content-Length: 40 Accept-Encoding: gzip, deflate, compress Accept: application/json User-Agent: Spotify API Console v0.1 Content-Type: application/json Authorization: "Authorization Code" {"name": "New Playlist", "public": true}enter code here

这是我在R控制台中获得的

POST /v1/users/121616946/playlists HTTP/1.1 Host: open.spotify.com User-Agent: libcurl/7.43.0 r-curl/1.2 httr/1.2.1 Accept-Encoding: gzip, deflate Accept: application/json Authorization: "Authorization Code" Content-Type: application/json Content-Length: 32 name=New%20Playlist1&public=true HTTP/1.1 404 Not Found Server: nginx Date: Fri, 25 Nov 2016 19:57:41 GMT Content-Type: text/html; charset=UTF-8 Transfer-Encoding: chunked Connection: keep-alive Keep-Alive: timeout=10 Vary: Accept-Encoding Cache-Control: no-cache Content-Encoding: gzip

Tl; Dr:我认为我的问题是POST的主体。我不认为我在通话中正确格式化了。我可能会遗漏别的东西,但我不确定是什么。授权令牌完全被授权执行我要求它做的事情,因此这不会是一个问题。

0 个答案:

没有答案