seems that with tweepy I can get only 200 tweets using user_timeline method.
class Twitter_User():
def __init__(self,id,count=200):
self.id = id
self.count = count
self.data = None
def get_tweets(self):
store_tweets = api.user_timeline(self.id, count=self.count)
simple_list = []
for status in store_tweets:
array = [status._json["text"].strip(), status._json["favorite_count"], status._json["created_at"],status._json["retweet_count"],[h["text"] for h in status._json["entities"]["hashtags"]]]
simple_list.append(array)
self.data = pd.DataFrame(simple_list, columns=["Text", "Like", "Created at","Retweet","Hashtags"])
self.data = self.data[~self.data["Text"].str.startswith('RT')]
return self.data
def __repr__(self):
id = api.get_user(self.id)
return id.screen_name
If I put as self.count a number bigger than 200, I always will get a dataframe with 200 rows, instead if I put a smaller number, I get the correct amount of rows. I don't know, there is a limit or I have to use some other method?
You can only get a maximum of 200 tweets in one request. However, you can make successive requests for older tweets. The maximum number of tweets that you can get in a timeline is 3200. The reference is here.
You can do this with tweepy but you will need to tweepy's Cursor get these successive pages of tweets. Look at this to get you started.
To get more then 200, you need to use the cursor
on user_timeline
and then iterate over the pages.
import tweepy
# Consumer keys and access tokens, used for OAuth
consumer_key = ''
consumer_secret = ''
access_token = ''
access_token_secret = ''
# OAuth process, using the keys and tokens
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# Creation of the actual interface, using authentication
api = tweepy.API(auth)
for pages in tweepy.Cursor(api.user_timeline, id='id', count=200).pages():
print(pages)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With