Created
October 24, 2013 03:33
-
-
Save chriskief/7130874 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import tweepy | |
| from django.conf import settings | |
| from django.core.urlresolvers import reverse | |
| from django.core.context_processors import csrf | |
| def get_authorization_url(request): | |
| # URL to where we will redirect to | |
| redirect_url = settings.SITE_URL + reverse('register_twitter') | |
| # create the handler | |
| auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET, redirect_url) | |
| # get the authorization url (i.e. https://api.twitter.com/oauth/authorize?oauth_token=XXXXXXX) | |
| # this method automatically grabs the request token first | |
| # Note: must ensure a callback URL (can be any URL) is defined for the application at dev.twitter.com, | |
| # otherwise this will fail (401 Unauthorized) | |
| try: | |
| url = auth.get_authorization_url() | |
| except tweepy.TweepError: | |
| # failed to get auth url (maybe twitter is down) | |
| url = reverse('home') | |
| return url | |
| # store the returned values | |
| request.session['twitter_request_token_key'] = auth.request_token.key | |
| request.session['twitter_request_token_secret'] = auth.request_token.secret | |
| return url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment