Reputation: 821
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?
Upvotes: 7
Views: 12802
Reputation: 1
Use tweepy cursor, #MuniLima is the tweeter account, #The list which are empty initially, they start with the For loop. to store tweeter values:'create_at','favourite_count','text'
tweeteo=[]
likes=[]
time = []
for tuit in tweepy.Cursor(api.user_timeline,screen_name='MuniLima').items(2870):
time.append(tuit.created_at)
likes.append(tuit.favorite_count)
tweeteo.append(tuit.text)
Upvotes: 0
Reputation: 10587
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)
Upvotes: 3
Reputation: 4048
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.
Upvotes: 10
Reputation: 10090
According to the Twitter API docs the most records you can retrieve from /statuses/user_timeline/
is 200
From the definition of the count parameter:
Specifies the number of Tweets to try and retrieve, up to a maximum of 200 per distinct request. The value of count is best thought of as a limit to the number of Tweets to return because suspended or deleted content is removed after the count has been applied. We include retweets in the count, even if include_rts is not supplied. It is recommended you always send include_rts=1 when using this API method.
And from the tweepy source code in api.py line 114:
@property
def user_timeline(self):
""" :reference: https://dev.twitter.com/rest/reference/get/statuses/user_timeline
:allowed_param:'id', 'user_id', 'screen_name', 'since_id', 'max_id', 'count', 'include_rts'
"""
return bind_api(
api=self,
path='/statuses/user_timeline.json',
payload_type='status', payload_list=True,
allowed_param=['id', 'user_id', 'screen_name', 'since_id',
'max_id', 'count', 'include_rts']
)
Upvotes: 2