如何通过API的SoundCloud添加注释 [英] How to add comments through the SoundCloud API

查看:171
本文介绍了如何通过API的SoundCloud添加注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过该API的SoundCloud要发表评论,但在看文档这似乎是不可能的,只能用于 /曲目/ {ID}方法/注释似乎是 GET 。当我尝试发送一个 POST 我收到了 HTTP错误:422 ,如果我用控制台我同样的情况拿到422也与ERROR_MESSAGE:身不能为空即使是这样我加入 =身体测试作为参数

任何想法,你应该如何通过API添加评论?

我可以看到,它似乎是可能的,例如红宝石SDK:

 #创建一个新的定时评论
注释= client.post(/曲目/#{} track.id /评论:注释= GT; {
  :身体=> 这是一个限时评论,
  :时间戳=> 1500
})

但我使用的Objective-C SDK,这是我的code到目前为止(它返回一个422):

 的NSMutableDictionary *字典= [的NSMutableDictionary dictionaryWithObject:内容forKey:@身体];
如果(时间戳> = 0)
{
    [字典的setObject:[的NSString stringWithFormat:@%i的,时间戳] forKey:@时间戳];
}* NSString的资源= [的NSString stringWithFormat:@曲目/%I /评论的TrackID][SCAPI performMethod:@POSTonResource:资源withParameters:字典方面:委托USERINFO:无];


解决方案

好吧,我能找到它在我自己,我看了一下Java版本和它的例子:

 列表<&的NameValuePair GT; PARAMS =新的java.util.ArrayList<&的NameValuePair GT;();
params.add(新BasicNameValuePair(发表评论[正文],这是一个测试评论));HTT presponse响应= api.post(曲目/+ TRACK_ID +/注释,则params);

于是奇怪的决定,不仅有作为关键,但注释[正文] 并没有记录它在API中是我有问题。我试图做这样建议确实有一个的NSDictionary 通过键评论红宝石版本并在另一个与时间戳但将只投错误,因为SDK没有想到嵌​​套的字典。所以,现在的code是这样的:

 的NSMutableDictionary *字典= [的NSMutableDictionary dictionaryWithObject:内容forKey:@的评论[正文]];
如果(时间戳> = 0)
{
    [字典的setObject:[的NSString stringWithFormat:@%i的,时间戳] forKey:@的评论[时间戳]];
}* NSString的资源= [的NSString stringWithFormat:@曲目/%I /评论的TrackID][SCAPI performMethod:@POSTonResource:资源withParameters:字典方面:委托USERINFO:无];

I would like to post comments via the SoundCloud API but looking at the documentation it seems impossible, the only method available for /tracks/{id}/comments seems to be GET. When I try to send it a POST I get a HTTP Error: 422, same happens if I use the console I get a 422 too, with "error_message": "Body can't be blank" even so I added body=test as a parameter.

Any idea how you are supposed to add a comments via the API?

I can see that it seems to be possible with for example the ruby SDK:

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

but I am using the Objective-C SDK and this is my code so far (which returns a 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];

解决方案

Ok, I was able to find it out on myself, I had a look at the Java version and its examples:

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);

So the strange decision to not only have bodyas the key but comment[body] and without documenting it in the API was what I had problems with. I tried to do it like the ruby version suggested do have a NSDictionary with the key comment and within another one with body and timestamp but that would just cast errors because the SDK didn't expect nested dictionaries. So now the code looks like this:

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];

这篇关于如何通过API的SoundCloud添加注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆