{% extends "default.html" %} {% block pagetitle %}API{% endblock %} {% block content %}
This page explains how to obtain and use an access token.
In the apps tab of {{SITE_NAME}} settings, fill in and submit the form to request an access token. You will need:
Don't worry too much about accuracy; you will be able to change all of these later.
{{SITE_NAME}} administrators will review and approve or deny your request for an access token. You'll know when your request has been approved when you get a private message with an access token tied to your account.
DO NOT reveal your Client ID or Access Token. Anyone with these information will be able to pretend to be you. You are responsible for keeping them a secret!
To use the access token, include the following header in subsequent API requests to {{SITE_NAME}}: Authorization: access_token_goes_here
Python example:
import requests headers = {"Authorization": "access_token_goes_here"} url = "{{SITE_FULL}}/?sort=comments" r = requests.get(url, headers=headers) print(r.json())
The expected result of this would be a large JSON representation of the posts on the frontpage sorted by the number of comments
Aother python example:
import requests headers = {"Authorization": "access_token_goes_here"} url = "{{SITE_FULL}}/unread" r = requests.get(url, headers=headers) print(r.json())
The expected result of this would be a JSON representation of unread notifications for your account
The OAuth4 authorization flow is used to enable users to authorize third-party applications to access their {{SITE_NAME}} account without having to provide their login information to the application.
This page explains how to obtain API application keys, how to prompt a user for authorization, and how to obtain and use access tokens.
In the apps tab of {{SITE_NAME}} settings, fill in and submit the form to request new API keys. You will need:
Don't worry too much about accuracy; you will be able to change all of these later.
{{SITE_NAME}} administrators will review and approve or deny your request for API keys. You'll know when your request has been approved when you get a private message with an access token tied to your account.
DO NOT reveal your Client ID or Access Token. Anyone with these information will be able to pretend to be you. You are responsible for keeping them a secret!
Send your user to {{SITE_FULL}}/authorize/?client_id=YOUR_CLIENT_ID
If done correctly, the user will see that your application wants to access their {{SITE_NAME}} account, and be prompted to approve or deny the request.
The user clicks "Authorize". {{SITE_NAME}} will redirect the user's browser to GET the designated redirect URI. The access token URL parameter will be included in the redirect, which your server should process.
To use the access token, include the following header in subsequent API requests to {{SITE_NAME}}: Authorization: access_token_goes_here
Python example:
import requests headers = {"Authorization": "access_token_goes_here"} url = "{{SITE_FULL}}/?sort=comments" r = requests.get(url, headers=headers) print(r.json())
The expected result of this would be a large JSON representation of the posts on the frontpage sorted by the number of comments
Aother python example:
import requests headers = {"Authorization": "access_token_goes_here"} url = "{{SITE_FULL}}/unread" r = requests.get(url, headers=headers) print(r.json())
The expected result of this would be a JSON representation of unread notifications for your account
{% endblock %}