Protocol Module#
This module contains only one class. This class handles interactions with the Strava V3 API including steps in the authentication process.
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’, ‘activity:read’, ‘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:
str
- 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:
client_id (int) – The numeric developer client id.
client_secret (str) – The developer client secret
code (str) – The temporary authorization code
- 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:
dict
- 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:
client_id (int) – The numeric developer client id.
client_secret (str) – The developer client secret
refresh_token (str) – The refresh token obtain from a previous authorization request
- 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:
dict
- 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.