将曲目添加到播放列表 SoundCloud API [英] Add track to playlist SoundCloud API
问题描述
在我的 Windows Phone 应用程序中,我使用以下代码向播放列表添加曲目(即对播放列表/id 端点的 PUT 请求)
In my Windows Phone App, I'm using the following code to add a track to playlist (i.e. a PUT request to playlists/id endpoint)
using (HttpClient httpClient = new HttpClient())
{
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AccessToken);
HttpResponseMessage response = await httpClient.PutAsync(endpoint, new StringContent(data));
response.EnsureSuccessStatusCode();
}
其中数据"是 JSON 数据的形式:
where "data" is JSON data the form:
{"playlist":{"tracks":["TrackId(to be added)"]}}
以上代码返回OK"(200) 响应,但曲目未添加到播放列表中!
The above code returns "OK"(200) response but the track is NOT added to the playlist!
我做错了什么?卡了两天.提前致谢!
What am I doing wrong? Stuck on it for two days. Thanks in advance!
推荐答案
问题是 JSON 数据(请求正文的)格式不正确.数据"必须采用以下形式:
The problem was that the JSON data (of the request body) was not formatted correctly. "data" must be of the form:
{"playlist":{"tracks":[{"id":"__"}, {"id":"__"}, {"id":"__"}]}}
此处必须存在 id-value 对
Here the id-value pair must be present for
播放列表中已经存在的每首曲目,以及
every track already present in the playlist, as well as
要添加到播放列表的曲目
the track that you want to add to the playlist
(请记住,这是一个 PUT 请求.因此,您需要更新数据,即更新播放列表"的tracks"属性)
(Remember, this is a PUT request. So, you need to update data i.e. update the "tracks" property of the "playlist")
这篇关于将曲目添加到播放列表 SoundCloud API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!