Skip to content

Instantly share code, notes, and snippets.

@glarrain
Created October 17, 2012 12:54
Show Gist options
  • Select an option

  • Save glarrain/3905363 to your computer and use it in GitHub Desktop.

Select an option

Save glarrain/3905363 to your computer and use it in GitHub Desktop.

Revisions

  1. glarrain renamed this gist Oct 17, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.py → tweets.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    from social_auth.backends.twitter import TwitterAuth


    def last_tweets(user):
    def get_last_tweets(user):
    try:
    social_auth = user.social_auth.filter(provider='twitter')[0]
    except IndexError:
  2. @omab omab created this gist Aug 22, 2012.
    22 changes: 22 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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 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)