-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathauthenticate_imgur.py
33 lines (21 loc) · 1003 Bytes
/
authenticate_imgur.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
#!/usr/bin/env python3
from imgurpython import ImgurClient
import config
CONFIG_FILE = "config.yaml"
def authenticate():
conf = config.read_file(CONFIG_FILE)
# Get client ID and secret from auth.ini
client = ImgurClient(conf.imgur.client_id, conf.imgur.client_secret)
# Authorization flow, pin example (see docs for other auth types)
authorization_url = client.get_auth_url('pin')
print("Go to the following URL: {0}".format(authorization_url))
# Read in the pin
pin = input("Enter pin code: ")
# ... redirect user to `authorization_url`, obtain pin (or code or token) ...
credentials = client.authorize(pin, 'pin')
client.set_user_auth(credentials['access_token'], credentials['refresh_token'])
print("Authentication successful! Here are the details:")
print(" Access token: {0}".format(credentials['access_token']))
print(" Refresh token: {0}".format(credentials['refresh_token']))
if __name__ == "__main__":
authenticate()