如何从用户列表中检索带有标签的推文 [英] How to retrieve hashtaged tweets from a list of users
问题描述
有没有办法在使用 1.1 的 Twitter API 的一次调用中从使用特定 #hashtag 标记的配置文件列表 (3) 中检索所有推文?
Is there a way retrieving all the tweets from a list of profiles (3) which are tagged with certain #hashtag in a single call to the Twitter API using 1.1?
如果没有,很明显,我会从每个用户那里检索一百条推文,并过滤掉那些没有 #hashtag 的推文……但效率不高,对吧?
If not, obviously, I'd be retrieving a hundred tweets from each user, and filtering out those which do not have the #hashtag .. but it's not very efficient, right?
提前致谢
推荐答案
注意:我已经更新了库 所以我建议你在尝试之前先获取最新更新的版本 - 我已经做到了,所以你不需要手动编码每个单独的字符.
Note: I've updated the library so I suggest you grab the newly updated version before trying this - I've made it so you don't need to manually encode each individual character.
此页面 向您展示了如何使用搜索,并且有许多运算符向下朝向页面底部.其中之一是 OR
运算符:
This page shows you how to use search, and has a number of operators down toward the bottom of the page. One of these is the OR
operator:
OR - 这个或那个
爱或恨 - 包含爱"或恨"(或两者)
来自 - 来自该用户
from:twitterapi 来自用户@twitterapi
因此,根据上述知识,我猜测您的查询将如下所示:
So, armed with the above knowledge, I'm guessing your query would look like this:
转换为 GET 请求:
?q=from:user1+OR+from:user2
这就是您为多个用户获取推文的方式.您想要的下一步是针对某些主题标签.
So that's how you get tweets for multiple users. The next step you want is for certain hashtags.
#haiku - 包含标签haiku"
单独翻译成正确的格式变成:
That translated individually into the correct format becomes:
?#haiku
(或 %2C haiku,取决于您使用的库/urlencoding)
标准 AND 运算符如下所示:
The standard AND operator looks like this:
twitter 搜索 - 包含twitter"和搜索".默认运算符
对于获取请求:
?twitter+search
让我们把这一切结合起来!
So let's combine all this!
?q=#hashtag1+#hashtag2+from:user1+OR+from:user2
而且,因为您使用的是 我的库,这里是代码:
And, because you're using my lib, here's the code for that:
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$requestMethod = 'GET';
$getfield = '?q=#hashtag1+OR+#hashtag2+from:username1+OR+from:username2';
$twitter = new TwitterAPIExchange($settings);
$json = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
var_dump(json_decode($json));
这篇关于如何从用户列表中检索带有标签的推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!