Created
September 17, 2012 13:53
-
-
Save gianni-di-noia/3737378 to your computer and use it in GitHub Desktop.
Twitter OAuth handler (gae/py, webapp2, tweepy)
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 webapp2, tweepy | |
consumer_token = 'CONSUMER KEY' | |
consumer_secret = 'CONSUMER SECRET' | |
auth = tweepy.OAuthHandler(consumer_token, consumer_secret) | |
class Twitter(webapp2.RequestHandler): | |
def get(self): | |
oauth_token = self.request.get("oauth_token") | |
oauth_verifier = self.request.get("oauth_verifier") | |
if oauth_token: | |
auth.get_access_token(oauth_verifier) | |
try: | |
api = tweepy.API(auth) | |
me = api.me() | |
self.response.write('Hi %s!' % me.name) | |
except: | |
auth_url = auth.get_authorization_url() | |
self.response.write("<a href='%s'>Twitter login</a>" % auth_url) | |
app = webapp2.WSGIapplication([('/', Twitter)]) | |
def main(): | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment