Skip to content

Instantly share code, notes, and snippets.

@vyahhi
Last active February 18, 2017 19:34
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vyahhi/0c639c7a17c4fc828cc0 to your computer and use it in GitHub Desktop.
Save vyahhi/0c639c7a17c4fc828cc0 to your computer and use it in GitHub Desktop.
How to use Stepic API with OAuth
# Run with Python 3
import json
import requests
# 1. Get your keys at https://stepic.org/oauth2/applications/ (client type = confidential, authorization grant type = client credentials)
client_id = ...
client_secret = ...
# 2. Get a token
auth = requests.auth.HTTPBasicAuth(client_id, client_secret)
resp = requests.post('https://stepic.org/oauth2/token/', data={'grant_type': 'client_credentials'}, auth=auth)
token = json.loads(resp.text)['access_token']
# 3. Call API (https://stepic.org/api/docs/) using this token.
# Example:
api_url = 'https://stepic.org/api/courses/67'
course = json.loads(requests.get(api_url, headers={'Authorization': 'Bearer '+ token}).text)
print(course)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment