How to Exclude retweets and replies in a search api? - javascript

How to Exclude retweets and replies in a search api?
I am trying to fetch the feeds from twitter using search api, in the result I am getting replies and retweets also.
So I want to exclude replies and retweets.
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

I beleive the above is incorrect, you can use filters in the search API but the documentation is very poor (non-existent?).
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

Old post, but people might still stumble upon it.
Most query operators are documented here: https://dev.twitter.com/rest/public/search
But for the search/tweets method, you can also specify exclude:replies and/or exclude:retweets to filter out replies and retweets from the result.
Just test it in the API Console Tool and see for yourself.
Bonus: Another undocumented query operator is filter:verified to get tweets from verified users.
Example query: cats filter:vine filter:verified exclude:replies exclude:retweets

In the new Search Tweets API, including the following parameters will remove different flavors of retweets:
-is:retweet Excludes retweets
-is:quote Excludes quote tweets
-is:reply Excludes replies
Please see the API documentation here: Search Tweets - Build a Query
Only Mike Chen's response (which oddly had 0 upvotes until I upvoted it) is correct. The rest of the answers here are out of date due to the launch of the Twitter API v2. I would comment directly on Mike's answer, but I don't have enough reputation.

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.
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

yes, you can exclude the retweets during search API by adding -RT in the search string (q). Ex: search?q="#demo -RT"

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

Found this while searching how to do this in the new v2 API, and it's now puppy -is:retweet -is:reply (no longer need the ANDs either)
https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query#list

According to the official documentation
Pass the following parameter exclude_replies=true

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_status typeof '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=0 is 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.
You could use something like so in a loop:
if(typeof tweets[i].retweeted_status === 'object') {tweets.splice(i,1);}
or
if(typeof tweets[i].retweeted_status !== 'undefined') {tweets.splice(i,1);}

There is no direct way to exclude retweets and replies from the api. However, you can filter out the results you have got.
For replies, you can check if the in_reply_to_status_id field you get from api is null, that means its not a reply else if it contains a id, then its a reply.
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

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
In the end you may use your RSS feed as a trigger for other web-applets through the self-hostable interface called Huginn

Related

Get Google Analytic View Id

I have JavaScript function to return list of google analytics account names for a given email address. I want to get view Id by giving account name or account Id.Is there any API or way to do this?
Considering using Account Summaries instead. It should give you a list of all accounts/properties/views. I think it will work better for you use case.
There is also a javascript example for calling it here.
I know that there aren't many JavaScript examples in these but have you tried checking out the official Google Analytics API and documentation? It makes things so much easier when you can go off of the given options and then convert them to JavaScript.

How to get Wikipedia article data from Freebase suggest response

I'm looking for a simple way to get data about a university (name, native_name, city etc) from the Wikipedia infobox after a user selects a university from Freebase suggest. The dataset returned from freebase, however, is very small and doesn't include the wikipedia link unfortunately.
Currently I am using the "name" property and making an ajax request to http://live.dbpedia.org/data/"+name+".json. This often works but while doing some tests it turned out the name doesn't always map directly to the correct page. Let me split my question in a few to make myself clear:
Is it possible to configure the Freebase suggest plugin so that the
response includes the wikipedia link?
OR is there a similar plugin that queries DBpedia directly and is as
simple and user-friendly as Freebase's?
OR, as a plan B, is there a way to send a request to
"live.dbpedia.org" so that it only returns me the json after
redirects? On the Wikipedia API I can send a "redirects" variable that does this. But then I'd have to parse the data myself…
The problem with the plan B is that nothing guarantees that the freebase object's name will ever lead me to the correct Wikipedia page. Even after the redirects…
I swear I've read a lot of API documentation but everything is extremely confusing and I chose not to read long tutorials about RDF, SPARQL and MQL because I really don't think the solution should be so complicated. I'm asking here because I really hope I'm missing a simple solution…
UPDATE
{
id: "/en/babes-bolyai_university",
lang: "en",
mid: "/m/08c4bf",
name: "Babeş-Bolyai University",
notable: {
id: "/education/university",
name: "College/University"
},
score: 37.733559
}
This is the result I get after selecting "Babeş-Bolyai University" in the suggest widget.
SOLUTION
I assumed I can't configure the Suggest widget to return more data, so after getting the Freebase ID of the object I just send another request, this time with a query specifically asking for the Wikipedia ID. I didn't know any MQL and couldn't find the name of the Freebase field with the Wikipedia ID. Maybe I'm stupid but the Freebase documentation really confuses me. In any case Tom Morris' answer and this question helped me build the query that returned what I wanted:
https://www.googleapis.com/freebase/v1/mqlread?query={"id":"/en/babes-bolyai_university","key":{"namespace":"/wikipedia/en_title","value":null}}
The strings in the result come with numeric codes for special unicode characters though (in my case Babe$0219-Bolyai_University). I've been able to convert the code with String.fromCharCode(parseInt(219, 16)) but if someone knows of a way to convert the whole string that would be helpful. Otherwise I can just make my own function replacing the "$dddd" pattern with the corresponding character.
Thanks for the help!
There isn't a DBpedia autosuggest comparable to Freebase Suggest as far as I'm aware.
Anything that's in Freebase can be retrieved with Suggest by using an MQL expressions in the output parameter. For simple things, e.g. names, aliases, the MQL is basically just a JSON snippet containing the relevant property name.
EDIT: The output parameter doesn't actually appear to be documented in the context of Suggest, but anything that isn't a Suggest parameter gets passed through transparently to the Freebase Search API, so you can use all of the stuff described here: https://developers.google.com/freebase/v1/search-output You can get as much or as little information as you require returned with each suggestion.
If you do need to query DBpedia, you should be using the Wikipedia/DBpedia key, which is not necessarily the same as the name. For English Wikipedia, the key is in the namespace /wikipedia/en or if you want the numeric Wikipedia ID in the namespace `/wikipedia/en_id'. Replace the 'en' with the appropriate language code if you want to query other language Wikipedias. These keys have some non-ASCII characters escaped, so if you need to unescape them, you can use the documentation here: http://wiki.freebase.com/wiki/MQL_key_escaping
You can update the "flyout_service_path" parameter. Here there is a description in the freebase suggest documentation (https://developers.google.com/freebase/v1/suggest). I'm using this configuration for to get all the keys of a entity.
$(inputClass).suggest(
{
"key" : _FREEBASE_API_KEY_BROWSER_APP,
"flyout_service_path":"/search?filter=(all mid:${id})&output=(notable:/client/summary description type /type/object/key)&key=${key}"
}
).bind("fb-select", this.fbSelectedHandler);
In the freebase response I can see now in the "output" parameter the "/type/object/key" with all the keys of the entity (wikipedia,etc..).
My question now is how I can acquire this data from output ?. In the "fb-select" event the "data" variable, don't carry this fields.
Some help, please..

Reddit Search API URL?

I'm trying to implement a search using reddit's api, but am not having much luck:
http://www.reddit.com/search.json?q=ferrari?jsonp=?
It's returning some json formatted text but no results.. If I search "cars", it returns 2 results, and the rest of my code won't recognize the objects. (Plus, I know there's more than 2 results for cars). Any idea on how to modify the URL?
Your URL looks wrong. I think you used a question mark instead of an amp to separate request variables.
I tried using http://www.reddit.com/search.json?q=ferrari and I got a lot of results in JSON format.
This will allow you to do the most basic search for reddit posts.
You can add other parameters, described on the reddit API page : http://www.reddit.com/dev/api#GET_search. You can also limit your search to one subreddit.
For example, to get the same results, sort by newest : http://www.reddit.com/search.json?q=ferrari&sort=new
It does work for me like so :
http://www.reddit.com/search.json?q=rest&jsonp=callback
and there is limit parameter which by default is 25 and the maximum is 100

I want my app to take the input as someone's twitter handle return the tweets over the last 1 week

I want to be able to find the tweets a particular user has made in the last 7 days. Sample code as to how to accomplish this would be of great help.
Unfortunately I do not believe Twitter exposes an endpoint to get only the number of tweets. You will have to fetch all the tweets for the period you are interested in, and then count them (or take the length of the array, or something along those lines).
I believe you can get the tweets you are looking for using the statuses/user_timeline API endpoint.
I imagine you would need to look at search/tweets in the API:
https://dev.twitter.com/docs/api/1.1/get/search/tweets

How to get top stories from Bing api

Okay, it seems that every question I post gets voted down, so I have went over the FAQ again, and I'm not sure what I'm doing wrong. If you are going to vote down the post, I would really appreciate some sort of comment or feedback letting me know what the stackoverflow community expects from a "good question" or how to properly ask I guess?.....
I'm having trouble figuring out how to get "Top news" or "Most popular" news from the Bing(azure) API.
I am able to search for "" and get all news results(most recent), but I can't figure out a way to pull the "Top news"(see top stories section here: http://www.bing.com/news?q=top+stories&FORM=Z9LH3 )
I've looked through the documentation with no luck, and searched google. Does anyone know if Bing offers this functionality as part of their API?
Any suggestions?
The best way to figure out a Bing API query is to use the Azure "Service Explorer" tool...
If you look at your initial URL you are simply looking at the news section with the query "top stories". In that case, I believe this is the query you're looking for:
https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27news%27&Query=%27top%20stories%27&Options=%27EnableHighlighting%27
Also, the documentation landing page for reference, describes the API parameters in some more detail.
The selected answer is incorrect.
According to Microsoft Support,
...bing.com and Bing Search API do not provide feature or query results parity...
The selected answer will return results from the News API which contain or are relevant to the Query top stories. It will not return the same results as the Bing.com News (Top Stories) page.
In the new API, the Breaking News query (an empty query parameter in Bing.com API v2) is not possible, as an empty query like https://api.datamarket.azure.com/Bing/Search/v1/Composite?Sources=%27news%27&Query=%27%27&Options=%27EnableHighlighting%27will return a small set of old (for me, October 2014) items.
I have a ticket in to Microsoft Support about this, and will update once I hear more.

Categories