问题不在于您的代码,当您使用较旧的刷新令牌生成访问令牌时,FitBit 会提供新的刷新令牌。您应该跟踪此刷新令牌以使您的代码正常工作。例如。
def fitbit_data(credentials):
client_id = os.environ.get("FITBIT_CLIENT_ID")
client_secret = os.environ.get("FITBIT_CLIENT_SECRET")
oauth = fitbit.FitbitOauth2Client(client_id=client_id,
client_secret=client_secret,
refresh_token=str(credentials.get('refresh_token')),
access_token=str(credentials.get('access_token')))
token = oauth.refresh_token()
update_refresh_token(token)
app_client = fitbit.Fitbit(client_id=client_id, client_secret=client_secret,
access_token=token.access_token, refresh_token=token.refresh_token)
steps = app_client.time_series(
resource='activities/steps',
period='1d'
)
return steps