{% extends "default.html" %} {% block title %}
import requests code=request.args.get("code") headers={"User-Agent": "sex"} url="/oauth/grant" data={"client_id": my_client_id, "client_secret": my_client_secret, "grant_type": "code", "code": code } r=requests.post(url, headers=headers, data=data) print(r.json())If everything is good, we will respond with the following (example) JSON body:
{ "access_token": #Access token "scopes": #Comma-separated list of scopes included in authorization "expires_at": #Unix epoch integer time at which access token expires "token_type": "Bearer" "refresh_token": #This key is omitted in temporary authorizations }Store the access and refresh tokens. You should also store expiration timestamp and the scopes list, so that you pre-emptively avoid sending requests to Drama that won't be accepted. ## Step 5: Using the Access Token To use the access token, include the following header in subsequent API requests to Drama: `Authorization: Bearer access_token_goes_here` Python example, presuming that the application has obtained a valid `read` authorization:
import requests headers={"Authorization": "Bearer " + access_token, "User-Agent": "Drama Reader v1 by @carpathianflorist"} url="/" r=requests.get(url, headers=headers) print(r.json())The expected result of this would be a large JSON representation of the submissions that make up the user's personal front page. {% endfilter %}
{% endblock %}