-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdo_auth.py
50 lines (35 loc) · 1.1 KB
/
do_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
38
39
40
41
42
43
44
45
46
47
48
49
50
import requests
from urllib.parse import urlencode, quote
from _credentials import *
def build_auth_url():
base_url = "https://stackoverflow.com/"
endpoint = "oauth"
params = {
"client_id": client_id,
"redirect_uri": "http://cs.cf.ac.uk/",
"scope": "no_expiry,access_team|stackoverflow.com/c/comsc",
}
auth_url = base_url + endpoint + "?" + urlencode(params, quote_via=quote)
return auth_url
def do_auth():
base_url = "https://stackoverflow.com/"
endpoint = "oauth/access_token/json"
params = {
"client_id": client_id,
"client_secret": client_secret,
"code": code,
"redirect_uri": "http://cs.cf.ac.uk/",
}
r = requests.post(base_url + endpoint, params)
print(r.json())
if __name__ == "__main__":
#
# Run build_auth_url to put the url together. Copy this url into a browser,
# auth the app, then copy the code from the address bar to the _credentials
#
# print(build_auth_url())
#
# Run do_auth and get the access_token. Store it in _credentials
#
print(do_auth())
pass