2013-12-11 135 views
0

我正在寻找搜索以下任何事情,哪个看上去最好的工作:搜索主题中提及与Twitter API

Regular mentions of a topic ABC (ABC) 
Hashtag mentions of a topic ABC (#ABC) 
@ mentions of a topic ABC (@ABC) 

如何使用API​​来搜索呢?有没有一种特定的方式来形成网址来搜索其中任何一个?例如,我目前使用https://api.twitter.com/1.1/statuses/user_timeline.json与指定的帐户。

编辑:例如,我希望能够获得本页显示的推文:https://twitter.com/search?q=%23FiveWordTechHorrors从开发者的角度来看,我该如何做到这一点?

回答

0
NSString *url = [NSString stringWithFormat:@"http://api.twitter.com/1.1/search/tweets.json?q=%@&result_type=recent&count=%i", toBeSearched, count]; 
url = [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 
SLRequest *twitterInfoRequest = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:[NSURL URLWithString:url] parameters:nil]; 
[twitterInfoRequest setAccount:twitterAccount]; 
[twitterInfoRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) { 
    if ([urlResponse statusCode] == 429) { 
     //Rate Limit Reached 
    } else if (error) { 
     // Check if there was an error 
    } 
    // Check if there is some response data 
    if (responseData) { 
     NSError *error = nil; 
     NSArray *result = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableLeaves error:&error]; 
     // Do Whatever you want to do, the result is an array of 'tweet objects' 
    } 
}]; 
+0

啊,我想我只是得到某种URL作为回应,但它看起来像你根据我的历史猜测了Objective-C? 虽然我从代码中收集URL,但我正在尝试使用它。所以你说的东西像'http://api.twitter.com/1.1/search/tweets.json?q = ABC&result_type = recent&count = 10' – muttley91

+0

你可以通过URL传递更多参数:https:/ /dev.twitter.com/docs/api/1/get/search –

+0

哦。我以为你问它的iOS。那么,该网址就是您在代码中找到的网址。 –