11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

TweepyのStatusオブジェクトをJSONに変換する

Last updated at Posted at 2014-08-27

jsonで書き出したい時に困ったけどドキュメント見てもググっても見つからなかったからメモ

結局 t._jsonで出来る(tはTweepyのStatusオブジェクト)。

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 										# ココ
	print json.dumps(t_json)

使う

$ python get_as_json.py CONSUMER_KEY CONSUMER_SECRET ACCESS_TOKEN ACCESS_TOKEN_SECRET user_name
11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?