-
Notifications
You must be signed in to change notification settings - Fork 5
/
auth.py
37 lines (26 loc) · 919 Bytes
/
auth.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
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import tweepy
from flask import Flask, redirect, request
app = Flask(__name__)
callback = "http://localhost:8000/callback"
session = {}
consumer_key = os.getenv("CONSUMER_KEY")
consumer_secret = os.getenv("CONSUMER_SECRET")
@app.route("/auth")
def auth():
auth = tweepy.OAuthHandler(consumer_key, consumer_secret, callback)
url = auth.get_authorization_url()
session["request_token"] = auth.request_token
return redirect(url)
@app.route("/callback")
def twitter_callback():
request_token = session["request_token"]
del session["request_token"]
auth = tweepy.OAuthHandler(consumer_key, consumer_secret, callback)
auth.request_token = request_token
verifier = request.args.get("oauth_verifier")
auth.get_access_token(verifier)
print(auth.access_token, auth.access_token_secret)
return redirect("/app")
if __name__ == "__main__":
app.run(port=8000)