Private
Public Access
1
0

v2/file now works

This commit is contained in:
Sander Roosendaal
2022-08-17 02:09:22 +02:00
parent ef1722f963
commit a7773a6f4a
3 changed files with 18 additions and 7 deletions

View File

@@ -17,7 +17,8 @@ from rowsandall_app.settings import (
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
TP_CLIENT_ID, TP_CLIENT_SECRET,
TP_REDIRECT_URI, TP_CLIENT_KEY,TP_API_LOCATION
TP_REDIRECT_URI, TP_CLIENT_KEY,TP_API_LOCATION,
TP_OAUTH_LOCATION,
)
tpapilocation = TP_API_LOCATION
@@ -50,7 +51,6 @@ def do_refresh_token(refreshtoken):
# Exchange access code for long-lived access token
def get_token(code):
# client_auth = requests.auth.HTTPBasicAuth(TP_CLIENT_KEY, TP_CLIENT_SECRET)
post_data = {
@@ -62,10 +62,13 @@ def get_token(code):
}
response = requests.post(
"https://oauth.trainingpeaks.com/oauth/token",
TP_OAUTH_LOCATION+"/oauth/token/",
data=post_data, verify=False,
)
if response.status_code != 200:
return 0,0,0
try:
token_json = response.json()
thetoken = token_json['access_token']
@@ -116,7 +119,7 @@ def tp_check(access_token): # pragma: no cover
'authorization': 'Bearer %s' % access_token
}
resp = requests.post(tpapilocation+"/v1/info/version",
resp = requests.post(tpapilocation+"/v2/info/version",
headers=headers, verify=False)
return resp
@@ -147,7 +150,7 @@ def uploadactivity(access_token, filename, description='',
"Data": base64.b64encode(data_gz.getvalue()).decode("ascii")
}
resp = requests.post(tpapilocation+"/v1/file",
resp = requests.post(tpapilocation+"/v2/file/synchronous",
data=json.dumps(data),
headers=headers, verify=False)

View File

@@ -1,4 +1,7 @@
from rowsandall_app.settings import NK_OAUTH_LOCATION, ROJABO_OAUTH_LOCATION
from rowsandall_app.settings import (
NK_OAUTH_LOCATION, ROJABO_OAUTH_LOCATION,
TP_OAUTH_LOCATION,
)
from rowers.views.statements import *
from rowers.plannedsessions import get_dates_timeperiod
@@ -295,7 +298,7 @@ def rower_tp_authorize(request): # pragma: no cover
"redirect_uri": TP_REDIRECT_URI,
"scope": "file:write",
}
url = "https://oauth.trainingpeaks.com/oauth/authorize/?" + \
url = TP_OAUTH_LOCATION+"oauth/authorize/?" + \
urllib.parse.urlencode(params)
return HttpResponseRedirect(url)

View File

@@ -328,6 +328,11 @@ try:
except KeyError:
TP_API_LOCATION = "https://api.trainingpeaks.com"
try:
TP_OAUTH_LOCATION = CFG['tp_oauth_location']
except KeyError:
TP_OAUTH_LOCATION = "https://oauth.trainingpeaks.com/oauth/token"
# RP3
RP3_CLIENT_ID = CFG["rp3_client_id"]
RP3_CLIENT_SECRET = CFG["rp3_client_secret"]