v2/file now works
This commit is contained in:
@@ -17,7 +17,8 @@ from rowsandall_app.settings import (
|
|||||||
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
C2_CLIENT_ID, C2_REDIRECT_URI, C2_CLIENT_SECRET,
|
||||||
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
STRAVA_CLIENT_ID, STRAVA_REDIRECT_URI, STRAVA_CLIENT_SECRET,
|
||||||
TP_CLIENT_ID, TP_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
|
tpapilocation = TP_API_LOCATION
|
||||||
@@ -50,7 +51,6 @@ def do_refresh_token(refreshtoken):
|
|||||||
|
|
||||||
# Exchange access code for long-lived access token
|
# Exchange access code for long-lived access token
|
||||||
|
|
||||||
|
|
||||||
def get_token(code):
|
def get_token(code):
|
||||||
# client_auth = requests.auth.HTTPBasicAuth(TP_CLIENT_KEY, TP_CLIENT_SECRET)
|
# client_auth = requests.auth.HTTPBasicAuth(TP_CLIENT_KEY, TP_CLIENT_SECRET)
|
||||||
post_data = {
|
post_data = {
|
||||||
@@ -62,10 +62,13 @@ def get_token(code):
|
|||||||
}
|
}
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
"https://oauth.trainingpeaks.com/oauth/token",
|
TP_OAUTH_LOCATION+"/oauth/token/",
|
||||||
data=post_data, verify=False,
|
data=post_data, verify=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if response.status_code != 200:
|
||||||
|
return 0,0,0
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token_json = response.json()
|
token_json = response.json()
|
||||||
thetoken = token_json['access_token']
|
thetoken = token_json['access_token']
|
||||||
@@ -116,7 +119,7 @@ def tp_check(access_token): # pragma: no cover
|
|||||||
'authorization': 'Bearer %s' % access_token
|
'authorization': 'Bearer %s' % access_token
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = requests.post(tpapilocation+"/v1/info/version",
|
resp = requests.post(tpapilocation+"/v2/info/version",
|
||||||
headers=headers, verify=False)
|
headers=headers, verify=False)
|
||||||
|
|
||||||
return resp
|
return resp
|
||||||
@@ -147,7 +150,7 @@ def uploadactivity(access_token, filename, description='',
|
|||||||
"Data": base64.b64encode(data_gz.getvalue()).decode("ascii")
|
"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),
|
data=json.dumps(data),
|
||||||
headers=headers, verify=False)
|
headers=headers, verify=False)
|
||||||
|
|
||||||
|
|||||||
@@ -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.views.statements import *
|
||||||
from rowers.plannedsessions import get_dates_timeperiod
|
from rowers.plannedsessions import get_dates_timeperiod
|
||||||
@@ -295,7 +298,7 @@ def rower_tp_authorize(request): # pragma: no cover
|
|||||||
"redirect_uri": TP_REDIRECT_URI,
|
"redirect_uri": TP_REDIRECT_URI,
|
||||||
"scope": "file:write",
|
"scope": "file:write",
|
||||||
}
|
}
|
||||||
url = "https://oauth.trainingpeaks.com/oauth/authorize/?" + \
|
url = TP_OAUTH_LOCATION+"oauth/authorize/?" + \
|
||||||
urllib.parse.urlencode(params)
|
urllib.parse.urlencode(params)
|
||||||
|
|
||||||
return HttpResponseRedirect(url)
|
return HttpResponseRedirect(url)
|
||||||
|
|||||||
@@ -328,6 +328,11 @@ try:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
TP_API_LOCATION = "https://api.trainingpeaks.com"
|
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
|
||||||
RP3_CLIENT_ID = CFG["rp3_client_id"]
|
RP3_CLIENT_ID = CFG["rp3_client_id"]
|
||||||
RP3_CLIENT_SECRET = CFG["rp3_client_secret"]
|
RP3_CLIENT_SECRET = CFG["rp3_client_secret"]
|
||||||
|
|||||||
Reference in New Issue
Block a user