rDrama/files/templates/api.html

130 lines
4.0 KiB
HTML
Raw Normal View History

2021-07-31 04:48:47 +00:00
{% extends "default.html" %}
2021-07-31 12:14:48 +00:00
{% block title %}
2021-08-03 06:17:48 +00:00
<title>{{"SITE_NAME" | app_config}} - API</title>
<meta name="description" content="{{"SITE_NAME" | app_config}} API Guide">
2021-07-31 12:14:48 +00:00
{% endblock %}
2021-07-31 09:18:59 +00:00
{% block content %}
2021-08-03 17:21:12 +00:00
<pre>
</pre>
2021-07-31 12:14:48 +00:00
{% filter markdown %}
2021-08-03 17:16:51 +00:00
# API Guide for Bots
2021-07-31 12:14:48 +00:00
2021-08-03 17:52:46 +00:00
<pre>
</pre>
2021-08-03 17:16:51 +00:00
This page explains how to obtain and use an access token.
2021-07-31 12:14:48 +00:00
## Step 1: Create your Application
2021-08-03 17:16:51 +00:00
In the [apps tab of {{"SITE_NAME" | app_config}} settings](/settings/apps), fill in and submit the form to request an access token. You will need:
2021-07-31 12:14:48 +00:00
* an application name
2021-08-03 17:16:51 +00:00
* a Redirect URI. May not use HTTP unless using localhost (use HTTPS instead).
* a brief description of what your bot is intended to do
2021-07-31 12:14:48 +00:00
Don't worry too much about accuracy; you will be able to change all of these later.
2021-08-03 17:16:51 +00:00
{{"SITE_NAME" | app_config}} 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.
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
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!
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
## Step 2: Using the Access Token
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
To use the access token, include the following header in subsequent API requests to {{"SITE_NAME" | app_config}}: `Authorization: access_token_goes_here`
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
Python example:
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
<pre>
import requests
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
headers={"Authorization": "access_token_goes_here", "User-Agent": "sex"}
2021-07-31 12:14:48 +00:00
2021-08-04 16:21:10 +00:00
url="{{request.host_url}}@carpathianflorist"
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
r=requests.get(url, headers=headers)
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
print(r.json())
</pre>
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
The expected result of this would be a large JSON representation of the posts posted by @carpathianflorist
2021-07-31 12:14:48 +00:00
2021-08-03 17:21:12 +00:00
<pre>
2021-07-31 12:14:48 +00:00
2021-08-03 17:21:12 +00:00
</pre>
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
# API Guide for Applications
2021-07-31 12:14:48 +00:00
2021-08-03 17:52:46 +00:00
<pre>
</pre>
2021-08-03 17:16:51 +00:00
The OAuth2 authorization flow is used to enable users to authorize third-party applications to access their {{"SITE_NAME" | app_config}} account without having to provide their login information to the application.
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
This page explains how to obtain API application keys, how to prompt a user for authorization, and how to obtain and use access tokens.
2021-07-31 12:14:48 +00:00
2021-08-03 17:16:51 +00:00
## Step 1: Create your Application
In the [apps tab of {{"SITE_NAME" | app_config}} settings](/settings/apps), fill in and submit the form to request new API keys. You will need:
* an application name
* a Redirect URI. May not use HTTP unless using localhost (use HTTPS instead).
* a brief description of what your application is intended to do
Don't worry too much about accuracy; you will be able to change all of these later.
{{"SITE_NAME" | app_config}} 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!
## Step 2: Prompt Your User for Authorization
2021-08-04 16:21:10 +00:00
Send your user to `{{request.host_url}}authorize/?client_id=YOUR_CLIENT_ID`
2021-08-03 17:16:51 +00:00
If done correctly, the user will see that your application wants to access their {{"SITE_NAME" | app_config}} account, and be prompted to approve or deny the request.
## Step 3: Catch the redirect
The user clicks "Authorize". {{"SITE_NAME" | app_config}} 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.
## Step 4: Using the Access Token
To use the access token, include the following header in subsequent API requests to {{"SITE_NAME" | app_config}}: `Authorization: access_token_goes_here`
Python example:
2021-07-31 12:14:48 +00:00
<pre>
import requests
2021-08-03 17:16:51 +00:00
headers={"Authorization": "access_token_goes_here", "User-Agent": "sex"}
2021-08-04 16:21:10 +00:00
url="{{request.host_url}}@carpathianflorist"
2021-07-31 12:14:48 +00:00
r=requests.get(url, headers=headers)
print(r.json())
</pre>
2021-08-03 17:16:51 +00:00
The expected result of this would be a large JSON representation of the submissions submitted by @carpathianflorist
2021-07-31 12:14:48 +00:00
{% endfilter %}
2021-07-31 12:16:54 +00:00
<pre>
</pre>
2021-07-31 04:48:47 +00:00
{% endblock %}