Protocol¶
Low-level classes for interacting directly with the Strava API webservers.
- class stravalib.protocol.ApiV3(access_token=None, requests_session=None, rate_limiter=None)[source]¶
Bases:
objectThis class is responsible for performing the HTTP requests, rate limiting, and error handling.
- server = 'www.strava.com'¶
- api_base = '/api/v3'¶
- authorization_url(client_id, redirect_uri, approval_prompt='auto', scope=None, state=None)[source]¶
Get the URL needed to authorize your application to access a Strava user’s information.
See https://developers.strava.com/docs/authentication/
- Parameters
client_id (int) – The numeric developer client id.
redirect_uri (str) – The URL that Strava will redirect to after successful (or failed) authorization.
approval_prompt (str) – Whether to prompt for approval even if approval already granted to app. Choices are ‘auto’ or ‘force’. (Default is ‘auto’)
scope (list[str]) – The access scope required. Omit to imply “read” and “activity:read” Valid values are ‘read’, ‘read_all’, ‘profile:read_all’, ‘profile:write’, ‘profile:read_all’, ‘activity:read_all’, ‘activity:write’.
state (str) – An arbitrary variable that will be returned to your application in the redirect URI.
- Returns
The URL to use for authorization link.
- Return type
- exchange_code_for_token(client_id, client_secret, code)[source]¶
Exchange the temporary authorization code (returned with redirect from strava authorization URL) for a short-lived access token and a refresh token (used to obtain the next access token later on).
- Parameters
- Returns
Dictionary containing the access_token, refresh_token and expires_at (number of seconds since Epoch when the provided access token will expire)
- Return type
- refresh_access_token(client_id, client_secret, refresh_token)[source]¶
Exchanges the previous refresh token for a short-lived access token and a new refresh token (used to obtain the next access token later on).
- Parameters
- Returns
Dictionary containing the access_token, refresh_token and expires_at (number of seconds since Epoch when the provided access token will expire)
- Return type
- get(url, check_for_errors=True, **kwargs)[source]¶
Performs a generic GET request for specified params, returning the response.
- post(url, files=None, check_for_errors=True, **kwargs)[source]¶
Performs a generic POST request for specified params, returning the response.