public
Created

Twitter OAuth handler (gae/py, webapp2, tweepy)

  • Download Gist
twitter.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
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()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.