Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting whole user timeline of a Twitter user

I want to get the all of a user tweets from one Twitter user and so far this is what I came up with:

import twitter
import json
import sys
import tweepy 
from tweepy.auth import OAuthHandler


CONSUMER_KEY = ''
CONSUMER_SECRET= ''
OAUTH_TOKEN=''
OAUTH_TOKEN_SECRET = ''

auth = twitter.OAuth(OAUTH_TOKEN,OAUTH_TOKEN_SECRET,CONSUMER_KEY,CONSUMER_SECRET)


twitter_api =twitter.Twitter(auth=auth)

print twitter_api

statuses = twitter_api.statuses.user_timeline(screen_name='@realDonaldTrump')
print [status['text'] for status in statuses]

Please ignore the unnecessary imports. One problem is that this only gets a user's recent tweets (or the first 20 tweets). Is it possible to get all of a users tweet? To my knowledge, the GEt_user_timeline (?) only allows a limit of 3200. Is there a way to get at least 3200 tweets? What am I doing wrong?

like image 770
Vin23 Avatar asked Feb 14 '17 11:02

Vin23


People also ask

How do you see someone else's timeline on Twitter?

How do I find a media timeline? Via twitter.com, go to the profile page of an account and click on the Media tab at the top of the Tweet timeline. From the Twitter for iOS or Android app, go to the profile of an account and tap Media.

How do I see all tweets from a user?

Scroll down to Accounts and in the From these accounts field, type in the username of the person whose tweets you want to search. You'll need to put in their exact @ name — you won't get suggestions. 4. Scroll back up to Words and specify what keywords or phrases you want to search that user's tweets for.

How do you get a timeline on Twitter?

Tap on the “Profile” icon on the top-left corner and open “Lists”. Now, tap on the “plus” icon at the bottom to create a Twitter List, in case you have not created any list. 2. After you are done making a list, tap on the “Pin” icon to move the particular list to the home screen.

What is user timeline in Twitter?

Your Home timeline displays a stream of Tweets from accounts you have chosen to follow on Twitter. You may see suggested content powered by a variety of signals. You can reply, Retweet, or like a Tweet from within Home.


1 Answers

There's a few issues with your code, including some superfluous imports. Particularly, you don't need to import twitter and import tweepy - tweepy can handle everything you need. The particular issue you are running into is one of pagination, which can be handled in tweepy using a Cursor object like so:

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 status in tweepy.Cursor(api.user_timeline, screen_name='@realDonaldTrump', tweet_mode="extended").items():
    print(status.full_text)
like image 77
asongtoruin Avatar answered Oct 26 '22 18:10

asongtoruin