2

我想通过 SoundCloud API 发表评论,但查看文档似乎是不可能的,唯一可用的方法/tracks/{id}/comments似乎是GET. 当我尝试发送它时,POST我得到一个HTTP Error: 422,如果我使用控制台我也会得到一个 422,"error_message": "Body can't be blank"即使这样我也添加body=test了一个参数。

知道您应该如何通过 API 添加评论吗?

我可以看到,例如 ruby​​ SDK 似乎是可能的:

# create a new timed comment
comment = client.post("/tracks/#{track.id}/comments", :comment => {
  :body => 'This is a timed comment',
  :timestamp => 1500
})

但我使用的是 Objective-C SDK,这是我目前的代码(返回 422):

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:content forKey:@"body"];
if (timestamp >= 0)
{
    [dict setObject:[NSString stringWithFormat:@"%i", timestamp] forKey:@"timestamp"];
}

NSString *resource = [NSString stringWithFormat:@"tracks/%i/comments", trackId];

[scAPI performMethod:@"POST" onResource:resource withParameters:dict context:delegate userInfo:nil];
4

2 回答 2

3

好的,我自己找到了,我查看了 Java 版本及其示例:

List<NameValuePair> params = new java.util.ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("comment[body]", "This is a test comment"));

HttpResponse response = api.post("tracks/" + TRACK_ID + "/comments", params);

所以这个奇怪的决定不仅body是关键,comment[body]而且没有在 API 中记录它是我遇到的问题。我尝试像 ruby​​ 版本建议的那样做,它有一个NSDictionarywith 键comment和另一个 with bodytimestamp但这只会抛出错误,因为 SDK 不期望嵌套字典。所以现在代码看起来像这样:

NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithObject:content forKey:@"comment[body]"];
if (timestamp >= 0)
{
    [dict setObject:[NSString stringWithFormat:@"%i", timestamp] forKey:@"comment[timestamp]"];
}

NSString *resource = [NSString stringWithFormat:@"tracks/%i/comments", trackId];

[scAPI performMethod:@"POST" onResource:resource withParameters:dict context:delegate userInfo:nil];
于 2012-05-27T10:02:23.923 回答
-1

这是一款出色的音乐应用程序,可让您轻松连接亚马逊最新的音乐、视频和电影,同时还可以自由创作其他产品。

于 2018-03-24T19:31:23.393 回答