冒号在Twitter API资源URL格式中意味着什么?

时间:2014-02-06 06:14:54

标签: api url twitter

用于转发的Twitter API显示为以下资源网址:

http://api.twitter.com/1/statuses/retweet/:id.format

然后它说“id”是必需的参数。

基于此,我认为以下AIFNetworking调用可行。我在哪里设置: postPath:@ “1.1 /状态/ retweet.json”

和参数: NSMutableDictionary * params = [NSMutableDictionary dictionaryWithDictionary:@ {@“id”:tweetID}];

整个电话看起来像:

- (void)postARetweet:(NSString*)tweetID success:(void (^)(AFHTTPRequestOperation *operation, id response))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure {

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{@"id": tweetID}];
self postPath:@"1.1/statuses/retweet.json" parameters:params success:success failure:failure];}

但我收到404错误,告诉我该页面不存在。经过多次试验和错误,我强迫postPath成为

postpath:@"1.1/statuses/retweet/@"some_tweet_number".json"

这很有效。

所以我不明白为什么“id”键的“params”条目没有像原来那样被附加到原始的postpath。我唯一想到的可能是postpath必须包含“id”,另外还有相同的“id”作为参数。

那么:id在资源URL中意味着什么? 为什么API要求推文的“id”成为URL路径的一部分,另外作为参数传递?似乎多余。

感谢

-Malena

1 个答案:

答案 0 :(得分:4)

让我们假设您要转发ID为123456的推文。该数字是:id

现在,让我们说您希望响应采用XML格式。这是format

所以你可以拥有

https://api.twitter.com/1.1/statuses/retweet/123456.xml

https://api.twitter.com/1.1/statuses/retweet/123456.json

请注意,API已更改为1.1版。您应该仔细阅读https://api.twitter.com/1.1/

上的文档

有关转发文档,请参阅https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid