This guide explains how to use the Authorization Window to get short-lived Threads user access tokens and permissions from Threads users.
The Authorization Window allows app users to grant your app permissions and short-lived Threads user access tokens. After a user logs in and chooses which data to allow your app to access, we will redirect the user to your app and include an authorization code, which you can then exchange for a short-lived access token.
To begin the process, get the Authorization Window and present it to the user:
https://threads.net/oauth/authorize ?client_id=<THREADS_APP_ID> &redirect_uri=<REDIRECT_URI> &scope=<SCOPE> &response_type=code &state=<STATE> // Optional
If accessing the Authorization Window from an Android mobile system, make sure to open the URL in the native webview or browser and not the native app.
An example of how you can achieve this with JavaScript:
window.open(url, '_system');`
Note: All parameters except state
are required.
Name | Description |
---|---|
numeric string
| Required. |
string
| Required. |
string
| Required. |
comma-separated or space-separated list
| Required. |
string
| An optional value indicating a server-specific state. For example, you can use this to protect against CSRF issues. We will include this parameter and value when redirecting the user back to you. |
https://threads.net/oauth/authorize ?client_id=990602627938098 &redirect_uri=https://socialsizzle.herokuapp.com/auth/ &scope=threads_basic,threads_content_publish &response_type=code
If authorization is successful, we will redirect the user to your redirect_uri and pass you an authorization code through the code query string parameter. Capture the code so your app can exchange if for a short-lived Threads User Access Token.
Authorization codes are valid for 1 hour and can only be used once.
https://socialsizzle.herokuapp.com/auth/?code=AQBx-hBsH3...#_
Note: #_
will be appended to the end of the redirect URI, but it is not part of the code itself, so strip it out.
If the user cancels the authorization flow, we will redirect the user to your redirect_uri
and append the following error parameters.
Note: It is your responsibility to fail gracefully in these situations and display an appropriate message to your users.
Error Parameter | Description |
---|---|
|
|
|
|
|
|
https://socialsizzle.herokuapp.com/auth/?error=access_denied &error_reason=user_denied &error_description=The+user+denied+your+request
Once you receive a code, exchange it for a short-lived access token by sending a POST
request to the following endpoint:
POST https://graph.threads.net/oauth/access_token
Include the following parameters in your POST
request body.
Name | Description |
---|---|
numeric string
| Required. |
string
| Required. |
string
| Required. |
string
| Required. |
string
| Required. |
curl -X POST \ https://graph.threads.net/oauth/access_token \ -F client_id=990602627938098 \ -F client_secret=eb8c7... \ -F grant_type=authorization_code \ -F redirect_uri=https://socialsizzle.herokuapp.com/auth/ \ -F code=AQBx-hBsH3...
If successful, the API will return a JSON payload containing the app user's short-lived access token and User ID.
{ "access_token": "THQVJ...", "user_id": 17841405793187218 }
Capture the access_token
value. This is the user’s short-lived Threads user access token, which your app can use to access Threads API endpoints.
If the request is malformed in some way, the API will return an error.
{ "error_type": "OAuthException", "code": 400, "error_message": "Matching code was not found or was already used" }