问题
According to their docs:
API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page])
Returns the 20 most recent statuses posted from the authenticating user or the user specified. It’s also possible to request another user’s timeline via the id parameter.
So how can I get more than 20 tweets from a person's timeline? The docs do not show how...Does that user need to be authenticated?
回答1:
You can make use of pages
parameter in API.user_timeline([id/user_id/screen_name][, since_id][, max_id][, count][, page])
. For page
value 1, you will get a set of latest 20 tweets from the user timeline and then in further iteration, when we increase the value of page = 2
then the method returns other 20 tweets which are older from the the oldest tweet received from page 1, You can think of this as:
Suppose you have 120 tweets in the account (1st tweet being the oldest and 120th tweet being the latest), then:
page = 1
would return (100, 120]
page = 2
would return (80, 100]... and so on
I hope you got the concept of pages now it's time to implement those things.
no_of_pages = int(raw_input("Please enter the number of tweets: "))
for i in xrange(no_of_pages):
API.user_timeline("@anmoluppal366", page = i)
回答2:
You can also use the max_id parameter. Something like
r0 = api.user_timeline("@donaldtrump") # gives 20 latest tweets
idlast = r0[-1].id # the last id of these 20
r1 = api.user_timeline("@donaldtrump", max_id = idlast) # next 20 tweets older or same age as idlast
来源:https://stackoverflow.com/questions/30406528/tweepy-how-can-i-get-more-than-20-tweets-from-a-user