Convert Tweepy Status object into JSON

后端 未结 3 1688
北荒
北荒 2020-12-01 01:41

I\'m using Tweepy to download tweets. I have a program that then writes the actual Status object to a file in text form. How do I translate this into JSON, or i

3条回答
  •  余生分开走
    2020-12-01 02:07

    A better way to do this is to use a tweepy parser. It's not documented very well - see the Tweepy API reference - but it's a public API, so much safer than using the _json property.

    import tweepy
    auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
    auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
    api = tweepy.API(auth, parser=tweepy.parsers.JSONParser())
    status = api.user_timeline(user=username, count=1)[0]
    json.dumps(status)
    

    status is now a json object.

提交回复
热议问题