使用Twitter API搜索主题提及

时间:2013-12-11 04:52:19

标签: twitter

我正在寻找以下任何一种东西,无论哪种效果最好:

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

如何使用API​​搜索此内容?是否有特定的方法来形成URL来搜索其中任何一个?例如,我目前正在使用https://api.twitter.com/1.1/statuses/user_timeline.json指定的帐户。

编辑:例如,我希望能够获得此页面上显示的推文:https://twitter.com/search?q=%23FiveWordTechHorrors如何从开发人员的角度来看?

1 个答案:

答案 0 :(得分: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'
    }
}];