使用 Twitter API 搜索主题的提及 [英] Search for Mentions of Topic with Twitter API

查看:22
本文介绍了使用 Twitter API 搜索主题的提及的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找以下任何一项,以最有效的方式为准:

I'm looking to search for any of the following things, whichever seems to work the best:

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.

How do I use the API to search this? Is there a specific way to form the URL to search for any one of these? For example, I'm currently using https://api.twitter.com/1.1/statuses/user_timeline.json with a specified account.

例如,我希望能够仅获取此页面上显示的推文:https://twitter.com/search?q=%23FiveWordTechHorrors 从开发人员的角度来看,我该如何做到这一点?

for example, I want to be able to get just the tweets that are shown on this page: https://twitter.com/search?q=%23FiveWordTechHorrors How do I do this from a developer point of view?

推荐答案

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

这篇关于使用 Twitter API 搜索主题的提及的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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