Last active
December 26, 2020 12:11
-
-
Save inactivist/5263501 to your computer and use it in GitHub Desktop.
How to get the raw Twitter API JSON response from a Tweepy request. It provides a simple way to stash the parsed API request results for later use. It stores the parsed JSON in a _payload field in the returned API results, which can then be iterated over. Not as clean as I'd like, but it allows me to leverage all of Tweepy's API methods and stil…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Taken from my suggestion at: | |
https://groups.google.com/forum/#!msg/tweepy/OSGRxOmkzL4/yaNT9fL9FAIJ | |
Note that this is an incomplete snippet; you'll need to create the API auth object. | |
""" | |
import simplejson as json | |
import tweepy | |
class MyModelParser(tweepy.parsers.ModelParser): | |
def parse(self, method, payload): | |
result = super(MyModelParser, self).parse(method, payload) | |
result._payload = json.loads(payload) | |
return result | |
api = tweepy.API(auth, parser=MyModelParser()) | |
results = api.user_timeline(screen_name='twitter') | |
for s in results._payload: | |
print json.dumps(s) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Gijs is right, this doesn't work for lists. I used
to overcome this