Javascript 如何在搜索 api 中排除转推和回复?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27941940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Exclude retweets and replies in a search api?
提问by rakesh r
How to Exclude retweets and replies in a search api?
如何在搜索 api 中排除转推和回复?
I am trying to fetch the feeds from twitter using search api, in the result I am getting replies and retweets also.
我正在尝试使用搜索 API 从 twitter 获取提要,结果我也收到了回复和转发。
So I want to exclude replies and excludes.
所以我想排除回复和排除。
How to do it anybody help me.
怎么办,谁帮帮我。
This is my url:
这是我的网址:
https://api.twitter.com/1.1/search/tweets.json?q=from:rioferdy5&count=20&result_type=recent
https://api.twitter.com/1.1/search/tweets.json?q=from:rioferdy5&count=20&result_type=recent
采纳答案by Hitesh
There is no direct way to exclude retweets and replies from the api. However, you can filter out the results you have got.
没有直接的方法可以从 api 中排除转推和回复。但是,您可以过滤掉您得到的结果。
For replies, you can check if the in_reply_to_status_idfield you get from api is null, that means its not a reply else if it contains a id, then its a reply.
对于回复,您可以检查in_reply_to_status_id从 api 获取的字段是否为空,这意味着它不是回复,否则如果它包含 id,则它是回复。
For retweet, if you want posts that have not been retweeted ever, you can check for retweet_count= 0 or if you want posts that have not been retweeted by your authenticated user, you can check for retweeted= false
对于转发,如果您想要从未转发过的帖子,您可以检查retweet_count= 0 或者如果您想要未经身份验证的用户转发的帖子,您可以检查retweeted= false
回答by Paul Thomas
I beleive the above is incorrect, you can use filters in the search API but the documentation is very poor (non-existent?).
我相信以上是不正确的,您可以在搜索 API 中使用过滤器,但文档很差(不存在?)。
Your query would become:
您的查询将变为:
?q=from:rioferdy AND -filter:retweets AND -filter:replies&count=20&result_type=recent
More tips for filtering were obtained here: How to Master Twitter Search: Basic Boolean Operators and Filters
此处获得了更多过滤技巧:如何掌握 Twitter 搜索:基本布尔运算符和过滤器
回答by phuc77
Old post, but people might still stumble upon it.
旧帖子,但人们可能仍然会偶然发现它。
Most query operators are documented here: https://dev.twitter.com/rest/public/search
大多数查询运算符都记录在此处:https: //dev.twitter.com/rest/public/search
But for the search/tweetsmethod, you can also specify exclude:repliesand/or exclude:retweetsto filter out replies and retweets from the result.
但是对于搜索/推文方法,您还可以指定exclude:replies和/或exclude:retweets从结果中过滤掉回复和转推。
Just test it in the API Console Tooland see for yourself.
只需在API 控制台工具中对其进行测试并亲自查看即可。
Bonus: Another undocumented query operator is filter:verifiedto get tweets from verified users.
奖励:另一个未记录的查询运算符是filter:verified从经过验证的用户那里获取推文。
Example query: cats filter:vine filter:verified exclude:replies exclude:retweets
示例查询: cats filter:vine filter:verified exclude:replies exclude:retweets
回答by Michael C
This is allowed as documented in the official documentation
这是允许的,如官方文档中所述
puppy -filter:retweets containing “puppy”, filtering out retweets
https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators.html
https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators.html
回答by Kehran
Very late reply, like everyone else but I feel the second answer here by Paul should be the "correct" one. I wish twitter would document this better, or make it more well known but there are a TON of search filters you can do, even with their standard API in 2018.
回复很晚,和其他人一样,但我觉得保罗在这里的第二个答案应该是“正确”的。我希望 twitter 能更好地记录这一点,或者让它更广为人知,但即使使用 2018 年的标准 API,你也可以做大量的搜索过滤器。
https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators
https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators
Here's a rather comphrensive list of examples :) and retweets is somewhere in the middle.
这是一个相当全面的示例列表:) 转发位于中间。
-filter:retweets
回答by ex0b1t
According to the official documentation
根据官方文档
Pass the following parameter exclude_replies=true
传递以下参数 exclude_replies=true
回答by JeremyS
Sorry I'm late to the party here. I agree with Hitesh in that they do not provide a way to exclude retweets natively, but every tweet that is a retweet has a retweet object in the json returned. So you could loop through your tweets and exclude any that have a retweeted_statustypeof 'object' (meaning they are a retweet from someone else) or keep those that have a typeof 'undefined' (meaning they are original). The issue with retweet_count=0is that someone like @pattonoswalt will have retweets on all of his tweets. So the count will never be zero even though they are all originals.
对不起,我来这里的派对迟到了。我同意 Hitesh 的观点,因为他们没有提供一种本地排除转推的方法,但是作为转推的每条推文在返回的 json 中都有一个转推对象。因此,您可以遍历您的推文并排除任何类型为retweeted_status“对象”的推文(意味着它们是来自其他人的转推)或保留类型为“未定义”的推文(意味着它们是原始的)。问题retweet_count=0在于像@pattonoswalt 这样的人会在他的所有推文上转发。因此,即使它们都是原件,计数也永远不会为零。
You could use something like so in a loop:
你可以在循环中使用类似的东西:
if(typeof tweets[i].retweeted_status === 'object') {tweets.splice(i,1);}
if(typeof tweets[i].retweeted_status === 'object') {tweets.splice(i,1);}
or
或者
if(typeof tweets[i].retweeted_status !== 'undefined') {tweets.splice(i,1);}
if(typeof tweets[i].retweeted_status !== 'undefined') {tweets.splice(i,1);}
回答by Prabin Kumar Das
yes, you can exclude the retweets during search API by adding -RTin the search string (q). Ex: search?q="#demo -RT"
是的,您可以通过添加-RT搜索字符串 (q)来排除搜索 API 期间的转推。前任:search?q="#demo -RT"
回答by gloschtla
Just use nitter.net it allows you to exclude things from the search results (via advanced search options on the right end of its search bar), and it even provides its own RSS feed. On top it expands these t.co short URLs and replaces the youtube URL with the invidio.us URL
只需使用 nitter.net,它就可以让您从搜索结果中排除某些内容(通过搜索栏右端的高级搜索选项),它甚至提供自己的 RSS 提要。最重要的是,它扩展了这些 t.co 短网址,并将 youtube 网址替换为 invidio.us 网址
In the end you may use your RSS feed as a trigger for other web-applets through the self-hostable interface called Huginn

