I am using tweepy and python 2.7.6 to return the tweets of a specified user
My code looks like:
import tweepy ckey = 'myckey' csecret = 'mycsecret' atoken = 'myatoken' asecret = 'myasecret' auth = tweepy.OAuthHandler(ckey, csecret) auth.set_access_token(atoken, asecret) api = tweepy.API(auth) stuff = api.user_timeline(screen_name = 'danieltosh', count = 100, include_rts = True) print stuff
However this yields a set of messages which look like<tweepy.models.Status object at 0x7ff2ca3c1050>
Is it possible to print out useful information from these objects? where can I find all of their attributes?
Steps to obtain keys: – For access token, click ” Create my access token”. The page will refresh and generate access token. Tweepy is one of the library that should be installed using pip. Now in order to authorize our app to access Twitter on our behalf, we need to use the OAuth Interface.
Returns full Tweet objects for up to 100 Tweets per request, specified by the id parameter.
If you need more than 100 Tweets, you have to use the paginator method and specify the limit i.e. the total number of Tweets that you want. Replace limit=1000 with the maximum number of tweets you want. Replace the limit=1000 with the maximum number of tweets you want (gist).
The API.retweets () method of the API class in Tweepy module is used to return a list of retweets of a tweet. id : The ID of the tweet which has to be retweeted. count : The number of retweets to be retrieved. Example 1 : List of users who retweeted the following tweet :
Tweepy explain itself as a “An easy-to-use Python library for accessing the Twitter API.” It is actually a library which uses Twitter API. Twitter has it’s own API to access features of itself. In short with Tweepy, it will be much easier to use Twitter API.
Now in order to authorize our app to access Twitter on our behalf, we need to use the OAuth Interface. Tweepy provides the convenient Cursor interface to iterate through different types of objects. Twitter allows a maximum of 3200 tweets for extraction.
Returns Tweets mentioning a single user specified by the requested user ID. By default, the most recent ten Tweets are returned per request. Using pagination, up to the most recent 800 Tweets can be retrieved. The Tweets returned by this endpoint count towards the Project-level Tweet cap.
Unfortunately, Status
model is not really well documented in the tweepy
docs.
user_timeline()
method returns a list of Status
object instances. You can explore the available properties and methods using dir()
, or look at the actual implementation.
For example, from the source code you can see that there are author
, user
and other attributes:
for status in stuff: print status.author, status.user
Or, you can print out the _json
attribute value which contains the actual response of an API call:
for status in stuff: print status._json
import tweepy import tkinter auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) # set parser=tweepy.parsers.JSONParser() if you want a nice printed json response. userID = "userid" user = api.get_user(userID) tweets = api.user_timeline(screen_name=userID, # 200 is the maximum allowed count count=200, include_rts = False, # Necessary to keep full_text # otherwise only the first 140 words are extracted tweet_mode = 'extended' ) for info in tweets[:3]: print("ID: {}".format(info.id)) print(info.created_at) print(info.full_text) print("\n")
Credit to https://fairyonice.github.io/extract-someones-tweet-using-tweepy.html
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