Please forgive me if this is a gross repeat of a question previously answered elsewhere, but I am lost on how to use the tweepy API search function. Is there any documentation available on how to search for tweets using the api.search()
function?
Is there any way I can control features such as number of tweets returned, results type etc.?
The results seem to max out at 100 for some reason.
the code snippet I use is as follows
searched_tweets = self.api.search(q=query,rpp=100,count=1000)
I originally worked out a solution based on Yuva Raj's suggestion to use additional parameters in GET search/tweets - the
max_id
parameter in conjunction with theid
of the last tweet returned in each iteration of a loop that also checks for the occurrence of aTweepError
.However, I discovered there is a far simpler way to solve the problem using a
tweepy.Cursor
(see tweepy Cursor tutorial for more on usingCursor
).The following code fetches the most recent 1000 mentions of
'python'
.Update: in response to Andre Petre's comment about potential memory consumption issues with
tweepy.Cursor
, I'll include my original solution, replacing the single statement list comprehension used above to computesearched_tweets
with the following:The other questions are old and the API changed a lot.
Easy way, with Cursor (see the Cursor tutorial). Pages returns a list of elements (You can limit how many pages it returns.
.pages(5)
only returns 5 pages):Where
q
is the query,count
how many will it bring for requests (100 is the maximum for requests) andtweet_mode='extended'
is to have the full text. (without this the text is truncated to 140 characters) More info here. RTs are truncated as confirmed jaycech3n.If you don't want to use
tweepy.Cursor
, you need to indicatemax_id
to bring the next chunk. See for more info.There's a problem in your code. Based on Twitter Documentation for GET search/tweets,
Your code should be,