Last active
February 18, 2017 19:34
-
-
Save vyahhi/0c639c7a17c4fc828cc0 to your computer and use it in GitHub Desktop.
How to use Stepic API with OAuth
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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