I am using twitter search api
https://dev.twitter.com/docs/using-search
I want to search for a word (exact match) and count the no of mentions or hashtags of that word (exact match).
I have tried q="json" OR #json OR #json but they retun something like json_decode or #json_dude but I want exact match.
Also, is there anyway to count the no of retweets without 'popular' search ?
In the page you linked, see the paragraph of "Search Operators", the 2nd example is what you are looking for. It says you sould use "
just like in a google search.
You cannot do exact search like this, there's no way.
You can do exact search only when you are not using `OR'
i.e. you can do q="json" but not q="json" OR #json OR #json.
But you can count the retweets by looking at field in_reply_to_status_id_str. Each in_reply_to_status_id_str represents that its a reply against a tweet , thus a retweet :)
Related
I'd like to extract all tweets in the Arabic language in all countries.
I modified the code in this tutorial.
This is my search query.
api.search(q="*", count=tweetsPerQry, lang ['ar'],tweet_mode='extended'). I expect to find a very large number of tweets, but I only collected about 7000 tweets.
I checked the content of some of them and I noticed that they are posted in my country even I did not specify the location/Country (Can anyone explain why this happen??).
I tried to know the reason for finding a limited number of tweets, so I modified the query by replacing the lang parameter by geocode to find tweets in a city. I fetched more than 65,000 Arabic tweets. After that, I used the lang parameter with the geocode and I found a very limited number of tweets.
Can anyone help me to know why I'm not able to get a large number of tweets when I used lang parameter?
The free twitter API's are good for small projects, but keep in mind that they don't display all of the tweets. Twitter has paid API's that are much more powerful, though what you are trying to achieve should be possible. I ran the query attached bellow, it seemed to work I was able to find a considerable amount of tweets. This method also seemed to work for #ebt_dev too I think it was just the structure of your request was set out like the stream listener version not the cursor search.
# Search Query change the X of .items(X) to the amount of tweets you are looking for
for tweet in tweepy.Cursor(api.search, q='*',tweet_mode='extended', lang='de').items(9999999):
# Defining Tweets Creators Name
tweettext = str( tweet.full_text.lower().encode('ascii',errors='ignore')) #encoding to get rid of characters that may not be able to be displayed
# Defining Tweets Id
tweetid = tweet.id
# printing the text of the tweet
print('\ntweet text: '+str(tweettext))
# printing the id of the tweet
print('tweet id: '+str(tweetid))
This page describes how to construct the query for twitter search. https://dev.twitter.com/rest/public/search
But it does not mention how to deal with the wildcard.
For example, if I want to search all keywords like this: smok*
smok* can represent Smoke, smoke, SMOKING, smoking, smoker etc. .
could I just simply say: q=smok* ?
I tried this, but it doesn't work. Could anyone help me ?
According to the search API documentation, there is no wildcard search available. Sorry.
I am using REST API to extract twitter search results in Hindi and Hebrew.
Search phrase in Hindi - "मुझे सपना आया" OR "मैंने सपना देखा की"
Twitter search results return about 100 results for this phrase - https://twitter.com/search?src=typd&q=%22%E0%A4%AE%E0%A5%88%E0%A4%82%E0%A4%A8%E0%A5%87%20%E0%A4%B8%E0%A4%AA%E0%A4%A8%E0%A4%BE%20%E0%A4%A6%E0%A5%87%E0%A4%96%E0%A4%BE%20%E0%A4%95%E0%A5%80%22%20OR%20%22%E0%A4%AE%E0%A5%81%E0%A4%9D%E0%A5%87%20%E0%A4%B8%E0%A4%AA%E0%A4%A8%E0%A4%BE%20%E0%A4%86%E0%A4%AF%E0%A4%BE%22
However Twitter explorer console API (https://dev.twitter.com/console) returns only 1 result.
Same thing happens for the Hebrew phrase as well. Website returns correct results. API only returns 1 result
Search phrase in Hebrew - "אתמול בלילה חלמתי"
Please Help!!
Thanks,
DB
Found out that for Twitter search api results only go back 1 week for exact phrase matches versus keyword matches. So changed my search criteria from exact phrases to separate words to solve the problem.
Here are the links from Twitter discussions which I found related to this topic.
https://dev.twitter.com/discussions/20596
https://dev.twitter.com/discussions/23726
When I try to console (With OAUTH) it returns more than 1 result.
If it doesn't for you try to make the count value higher.
this is my result:
http://pastebin.com/H2HVs71G
-Tim
I'd like to retrieve the tweets for given a hashtag and sort them from the most retweeted to the less retweeted.
The closest thing I've found is using the search call and use the type tag:
E.g.: http://search.twitter.com/search.json?q=TheHashTagHere&result_type=popular
However, I'm not sure on how "popular" option works.
For instance, if it finds 100 tweets with that hashtag I believe it should show the X most retweeted tweets, and if none of those tweets have been retweeted then it should show X of them randomly (or sorted in some other way like the most recent).
Unfortunately, if follows some kind of unknown rule to identify what's popular and what not and even hashtags with thousands of tweets might return only one or two results.
I hope I made myself clear. Thanks in advance :)
PS: I'll use PHP but I think that shouldn't affect the question?
Results will sometimes contain a
result_type field into the metadata
with a value of either "recent" or
"popular". Popular results are derived
by an algorithm that Twitter computes,
and up to 3 will appear in the default
mixed mode that the Search API
operates under. Popular results
include another node in the metadata
called recent_retweets. This field
indicates how many retweets the Tweet
has had.
Source (Emphasis are mine)
Just call with result_type=popular and check the recent_retweets node to see how popular it is. result_type=popular will become the default in an upcome release so beware if you omit this parameter.
Results with popular tweets aren't ordered chronologically. *
If you would like to always have results to show, use result_type=mixed: they will have the result_type in the "metadata" section with a value of "recent", and popular results will have "popular". A small reference about result_types:
mixed: Include both popular and real time results in the response.
recent: return only the most recent results in the response
popular: return only the most popular results in the response.
If a search query has any popular results, those will be returned at the top, even if they are older than the other results. *
*[Twitter API Announcements]
This isn't a programmatic method but rather works in the browser with a chrome extension (HackyBird) :
Install the extension
Search for a phrase e.g. #Social (twitter.com/search?q=%23Social)
Click the extension to sort it (you can adjust the ratio of retweets/likes used for sorting in extension options).
P.S. It'll also sort your or any other user's timeline.
Can I fetch all the tweets from users of a particular location filtered by a particular keyword?
For example, I want to look up all the tweets made during a day in a particular location with a keyword "XYZ". Can this be done?
Yep, you can use the form on http://search.twitter.com/advanced to construct an advanced query.
Also check out http://dev.twitter.com/doc/get/search for more API info.
So, for example, finding tweets containing "very nice" from users located within 100 miles from Los Angeles would be written as:
near:"Los Angeles" within:100mi "very nice"
Your search URL would then look like:
http://search.twitter.com/search?q=near%3A%22Los+Angeles%22+within%3A100mi+%22very+nice%22
You can also get these results in JSON or ATOM format but you'll need to include the geocode parameter that the search page generates. Easiest way to find this is to copy the param from the "Feed for this query" link on the top-right of the page.
So, results in JSON format:
http://search.twitter.com/search.json?geocode=34.052187%2C-118.243425%2C25.0km&q=near%3A%22Los+Angeles%22+within%3A100mi+%22very+nice%22
Results in ATOM format:
http://search.twitter.com/search.atom?geocode=34.052187%2C-118.243425%2C25.0km&q=near%3A%22Los+Angeles%22+within%3A100mi+%22very+nice%22
Specifying a date range is also possible; use the advanced search form to help you construct what you need.