Created
October 17, 2012 12:54
-
-
Save glarrain/3905363 to your computer and use it in GitHub Desktop.
Retrieve a user's last tweets
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
from urllib2 import urlopen | |
from django.utils.simplejson import loads | |
from oauth2 import Token | |
from social_auth.backends.utils import build_consumer_oauth_request | |
from social_auth.backends.twitter import TwitterAuth | |
def get_last_tweets(user): | |
try: | |
social_auth = user.social_auth.filter(provider='twitter')[0] | |
except IndexError: | |
return [] | |
request = build_consumer_oauth_request( | |
TwitterAuth, | |
Token.from_string(social_auth.extra_data['access_token']), | |
'https://api.twitter.com/1/statuses/home_timeline.json' | |
) | |
response = '\n'.join(urlopen(request.to_url()).readlines()) | |
return loads(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment