-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstravainky_getaccesstoken.py
36 lines (30 loc) · 1.22 KB
/
stravainky_getaccesstoken.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
import json
import os
import requests
import time
# Initial Settings
# Get data from config.py file
from config import client_id, client_secret
from config import redirect_uri, refresh_token
redirect_uri = 'http://localhost/'
# Authorization URL
request_url = f'http://www.strava.com/oauth/authorize?client_id={client_id}' \
f'&response_type=code&redirect_uri={redirect_uri}' \
f'&approval_prompt=force' \
f'&scope=profile:read_all,activity:read_all'
# User prompt showing the Authorization URL
# and asks for the code
print('Click here:', request_url)
print('Please authorize the app and copy&paste below the generated code!')
print('P.S: you can find the code in the URL')
code = input('Insert the code from the url: ')
# Get the access token
tokens = requests.post(url='https://www.strava.com/api/v3/oauth/token',
data={'client_id': client_id,
'client_secret': client_secret,
'code': code,
'grant_type': 'authorization_code'})
#Save json response as a variable
strava_tokens = tokens.json()
with open('strava_tokens.json', 'w') as outfile:
json.dump(strava_tokens, outfile)