使用stravalib的示例代码,我一直致力于理解程序的工作原理如下:
from stravalib import Client
code = request.args.get('code') # e.g.
client = Client()
access_token = client.exchange_code_for_token(client_id="Mas Rosenberg",
client_secret="***********************************",
code='code')
client = Client(access_token)
athlete = client.get_athlete()
print("Hello, {}".format(athlete.firstname))
'代码'用#例如它旁边应该是什么?
答案 0 :(得分:0)
以防万一其他人遇到麻烦,我遵循了这个略有不同的教程: link here(这家伙的全部功劳!)。 在这里,您首先刷新访问令牌:
import requests
from datetime import datetime
from stravalib.client import Client
import urllib3
urllib3.disable_warnings()
auth_url ="https://www.strava.com/oauth/token"
payload = {
'client_id' : CLIENT_ID,
'client_secret' : CLIENT_SECRET,
'refresh_token' : REFRESH_TOKEN,
'grant_type' : "refresh_token",
'f':'json'
}
print("Requesting the token...\n")
res = requests.post(auth_url,data=payload,verify=False)
print(res.json())
print()
access_token = res.json()['access_token']
expiry_ts = res.json()['expires_at']
print("New token will expire at: ",end='\t')
print(datetime.utcfromtimestamp(expiry_ts).strftime('%Y-%m-%d %H:%M:%S'))
client = Client(access_token=access_token)
athlete = client.get_athlete()
print(f'Hello {athlete.firstname} {athlete.lastname}')
登录后即可访问令牌CLIENT_ID,CLIENT_SECRET,REFRESH_TOKEN