Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

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

View twitter.py
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.