Enter code here...from __future__ import print_function
import time
import swagger_client
from swagger_client.rest import ApiException
from pprint import pprint
# Configure OAuth2 access token for authorization: strava_oauth
swagger_client.configuration.access_token = 'MY TOKEN'
# create an instance of the API class
api_instance = swagger_client.ClubsApi()
id = <MY CLUB> # Integer | The identifier of the club.
page = 56 # Integer | Page number. (optional)
perPage = 56 # Integer | Number of items per page. Defaults to 30. (optional) (default to 30)
try:
# List Club Activities
api_response = api_instance.get_club_activities_by_id(id, page=page, per_page=perPage)
pprint(api_response)
except ApiException as e:
print("Exception when calling ClubsApi->getClubActivitiesById: %s\n" % e)
Exception when calling ClubsApi->getClubActivitiesById: (401)
Reason: Unauthorized
HTTP response headers: HTTPHeaderDict({'Date': 'Mon, 04 Jun 2018 08:04:52 GMT', 'Content-Type': 'application/json; charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Cache-Control': 'no-cache', 'Via': '1.1 linkerd', 'Status': '401 Unauthorized', 'X-Request-Id': 'ac85febd-9ee4-4dd1-aeb9-a5c1cec0fafc', 'X-FRAME-OPTIONS': 'DENY', 'X-Content-Type-Options': 'nosniff', 'X-XSS-Protection': '1; mode=block'})
HTTP response body: {"message":"Authorization Error","errors":[{"resource":"Application","field":"","code":"invalid"}]}
I'm pretty sure the token is correct. If I go to the Oauth Authorization Page and click Authorize, I get the "It Works!" message. Am I missing something?
URI uri = new URI("https://www.strava.com/oauth/token");
URL url = uri.toURL();
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
try {
StringBuilder sb = new StringBuilder();
sb.append("client_id=" + CLIENT_ID);
sb.append("&client_secret=" + stravaScret);
sb.append("&code=" + accessToken);
conn.setRequestMethod("POST");
conn.setRequestProperty("Accept", "application/json");
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
os.write(sb.toString().getBytes("UTF-8"));
.......
......
Then you receive a access code which you then need to use along side your client_Secerte to do calls. i.e. getClubActivitiesById
Hope this helps
self.access_token = ""
Enter code here...swagger_client.configuration.access_token = 'MY TOKEN'