I was in trouble when I wanted to export with json, but I could not find it even if I looked at the document or googled, so a memo
After all, you can do it with t._json
( t
is Tweepy's Status object).
get_as_json.py
import sys
import tweepy
import json
consumer_key = sys.argv[1]
consumer_secret = sys.argv[2]
access_token = sys.argv[3]
access_token_secret = sys.argv[4]
screen_name = sys.argv[5]
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
client = tweepy.API(auth)
tweets = client.user_timeline(screen_name=screen_name)
for t in tweets:
t_json = t._json #Here
print json.dumps(t_json)
use
$ python get_as_json.py CONSUMER_KEY CONSUMER_SECRET ACCESS_TOKEN ACCESS_TOKEN_SECRET user_name
Recommended Posts