Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I retrieve all Tweets and attributes for a given user using Python?
    primarykey
    data
    text
    <p>I am attempting to retrieve data from Twitter, using Tweepy for a username typed at the command line. I'm wanting to extract quite a bit of data about the status and user,so have come up with the following:</p> <p>Note that I am importing all the required modules ok and have oauth + keys (just not included it here) and filename is correct, just been changed:</p> <pre><code># define user to get tweets for. accepts input from user user = tweepy.api.get_user(input("Please enter the twitter username: ")) # Display basic details for twitter user name print (" ") print ("Basic information for", user.name) print ("Screen Name:", user.screen_name) print ("Name: ", user.name) print ("Twitter Unique ID: ", user.id) print ("Account created at: ", user.created_at) timeline = api.user_timeline(screen_name=user, include_rts=True, count=100) for tweet in timeline: print ("ID:", tweet.id) print ("User ID:", tweet.user.id) print ("Text:", tweet.text) print ("Created:", tweet.created_at) print ("Geo:", tweet.geo) print ("Contributors:", tweet.contributors) print ("Coordinates:", tweet.coordinates) print ("Favorited:", tweet.favorited) print ("In reply to screen name:", tweet.in_reply_to_screen_name) print ("In reply to status ID:", tweet.in_reply_to_status_id) print ("In reply to status ID str:", tweet.in_reply_to_status_id_str) print ("In reply to user ID:", tweet.in_reply_to_user_id) print ("In reply to user ID str:", tweet.in_reply_to_user_id_str) print ("Place:", tweet.place) print ("Retweeted:", tweet.retweeted) print ("Retweet count:", tweet.retweet_count) print ("Source:", tweet.source) print ("Truncated:", tweet.truncated) </code></pre> <p>I would like this eventually to iterate through all of a user's tweets (up to the 3200 limit). First things first though. So far though I have two problems, I get the following error message regarding retweets: </p> <pre><code>Please enter the twitter username: barackobamaTraceback (most recent call last): File " usertimeline.py", line 64, in &lt;module&gt; timeline = api.user_timeline(screen_name=user, count=100, page=1) File "C:\Python32\lib\site-packages\tweepy-1.4-py3.2.egg\tweepy\binder.py", line 153, in _call raise TweepError(error_msg) tweepy.error.TweepError: Twitter error response: status code = 401 Traceback (most recent call last): File "usertimeline.py", line 42, in &lt;module&gt; user = tweepy.api.get_user(input("Please enter the twitter username: ")) File "C:\Python32\lib\site-packages\tweepy-1.4-py3.2.egg\tweepy\binder.py", line 153, in _call raise TweepError(error_msg) tweepy.error.TweepError: Twitter error response: status code = 404 </code></pre> <p>Passing the username as a variable seems to be a problem also: </p> <pre><code>Traceback (most recent call last): File " usertimleline.py", line 64, in &lt;module&gt; timeline = api.user_timeline(screen_name=user, count=100, page=1) File "C:\Python32\lib\site-packages\tweepy-1.4-py3.2.egg\tweepy\binder.py", line 153, in _call raise TweepError(error_msg) tweepy.error.TweepError: Twitter error response: status code = 401 </code></pre> <p>I've isolated both these errors, i.e. they aren't working together. </p> <p>Forgive my ignorance, I am not too hot with Twitter APIs but am learning pretty rapidly. Tweepy documentation really does suck and I've done loads of reading round on the net, just can't seem to get this fixed. If I can get this sorted, i'll be posting up some documentation. </p> <p>I know how to transfer the data into an MySQL db once extracted (it will do that, rather than print to screen) and manipulate it so that I can do stuff with it, it is just getting it out that I am having the problems with. Does anyone have any ideas or is there another method I should be considering? </p> <p>Any help really appreciated. Cheers</p> <p>EDIT: </p> <p>Following on from @Eric Olson's suggestion this morning; I did the following. </p> <p>1) Created a completely brand new set of Oauth credentials to test. 2) Copied code across to a new script as follows: </p> <p>Oauth</p> <pre><code>consumer_key = "(removed)" consumer_secret = "(removed)" access_key="88394805-(removed)" access_secret="(removed)" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api=tweepy.API(auth) # confirm account being used for OAuth print ("API NAME IS: ", api.me().name) api.update_status("Using Tweepy from the command line") </code></pre> <p>The first time i run the script, it works fine and updates my status and returns the API name as follows: </p> <pre><code>&gt;&gt;&gt; API NAME IS: Chris Howden </code></pre> <p>Then from that point on I get this: </p> <pre><code>Traceback (most recent call last): File "C:/Users/Chris/Dropbox/Uni_2012-3/6CC995 - Independent Studies/Scripts/get Api name and update status.py", line 19, in &lt;module&gt; api.update_status("Using Tweepy frm the command line") File "C:\Python32\lib\site-packages\tweepy-1.4-py3.2.egg\tweepy\binder.py", line 153, in _call raise TweepError(error_msg) tweepy.error.TweepError: Twitter error response: status code = 403 </code></pre> <p>The only reason I can see for it doing something like this is that it is rejecting the generated access token. I shouldn't need to renew the access token should I?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload