Since I usually use twitter, I want to post and get the timeline using a program, so I'll leave it here as a reminder to do that.
The following contents are described here. B. Acquisition of timeline B. To see the information contained in a tweet
In addition, the environment etc. is the same as Posting tweets with python, and it is assumed that you have acquired the API key.
To get the timeline, you need the following URL, The timeline that can be acquired changes by changing the parameters.
twitter_access.py
url = "https://api.twitter.com/1.1/statuses/home_timeline.json"
params = {"count":200, #How many tweets to get from the latest(Up to 200)
"include_entities" : 1, #entity(Image URL, etc.)To include in tweets
"exclude_replies" : 1, #Whether to include a reply
}
req = sess.get(url, params=params)
timeline = json.loads(req.text)
This will lexicographically assign tweets to the list named timeline.
If you want to see the tweets one by one, use a for sentence or the like.
twitter_access.py
for tweet in timeline:
print(tweet["text"])
Dictionary-type tweets have the following keys.
'is_quote_status', 'in_reply_to_user_id_str', 'place', 'geo', 'retweet_count', 'id_str', 'id', 'contributors', 'user', 'retweeted', 'text', 'in_reply_to_user_id', 'lang', 'in_reply_to_screen_name', 'truncated', 'source', 'favorite_count', 'created_at', 'entities', 'favorited', 'in_reply_to_status_id_str', 'coordinates', 'in_reply_to_status_id'
You can get various elements with this key. If you use'text' as an example, you can get the body of the tweet as a string. The information of the user who tweeted is stored in user in a dictionary type.
The user key is as follows.
'url', 'profile_background_tile', 'screen_name', 'profile_image_url', 'following', 'has_extended_profile', 'statuses_count', 'profile_background_color', 'profile_sidebar_fill_color', 'contributors_enabled', 'notifications', 'listed_count', 'translator_type', 'id', 'profile_background_image_url', 'profile_image_url_https', 'profile_link_color', 'profile_background_image_url_https', 'favourites_count', 'profile_banner_url', 'friends_count', 'location', 'default_profile_image', 'lang', 'verified', 'follow_request_sent', 'profile_use_background_image', 'profile_text_color', 'geo_enabled', 'protected', 'followers_count', 'description', 'is_translator', 'id_str', 'created_at', 'name', 'entities', 'time_zone', 'profile_sidebar_border_color', 'is_translation_enabled', 'utc_offset', 'default_profile'
Also, sometimes the tweet key has a key called extended_entities. The dictionary type is also stored in this key, and there is another key called media_url in the key called media. Inside this is the URL of the image that accompanies the tweet.
Probably not next.
Recommended Posts