Get a User Access Token
Exchanges an authorization code for a user access token and refresh token. Call this endpoint from your server after your redirect URI receives the authorization code.
Endpoint
HTTP URL |
|
HTTP method |
|
Scopes |
|
Content type |
|
Request
Send all parameters as URL-encoded form data in the request body.
Headers
Field | Type | Description | Required |
|
| The media type of the request body. Must be | Yes |
Request body
Field | Type | Description | Required |
|
| The client key from your app's App credentials section. | Yes |
|
| The client secret from your app's App credentials section. | Yes |
|
| The URL-decoded authorization code from the web, iOS, Android, or desktop authorization callback. | Yes |
|
| The OAuth grant type. Must be | Yes |
|
| The redirect URI from the authorization request. Must exactly match that value. | Yes |
|
| Required for mobile and desktop apps. The PKCE code verifier you used to generate the code challenge in the authorization request. | Conditional |
Request example
curl --location --request POST 'https://open.tiktokapis.com/v2/oauth/token/' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cache-Control: no-cache' \
--data-urlencode 'client_key=CLIENT_KEY' \
--data-urlencode 'client_secret=CLIENT_SECRET' \
--data-urlencode 'code=CODE' \
--data-urlencode 'grant_type=authorization_code' \
--data-urlencode 'redirect_uri=REDIRECT_URI'For mobile and desktop apps, also pass --data-urlencode 'code_verifier=CODE_VERIFIER', where CODE_VERIFIER is the code verifier from the authorization request.
Response
A successful request returns the following fields as JSON. Store them on your server.
Response body
Field | Type | Description |
|
| The access token for API calls on behalf of the user. |
|
| The number of seconds until the access token expires. The access token is valid for 2 hours after initial issuance. |
|
| The token for getting a new access token. |
|
| The number of seconds until the refresh token expires. The refresh token is valid for 180 days after the initial issuance. Refresh tokens are rotated: a successful refresh request returns a new |
|
| The TikTok user's unique identifier. |
|
| A comma-separated list of the scopes the user authorized. |
|
| The token type. Always |
Make sure to store these values on your backend as they are needed to persist access.
Response example
If the request is successful, the response will look like the following.
{
"error": "invalid_request",
"error_description": "Redirect_uri is not matched with the uri when requesting code.",
"log_id": "202206221854370101130062072500FFA2"
}If the request is not successful, an error response body will be returned, like the following.
{
"error": "invalid_request",
"error_description": "Redirect_uri is not matched with the uri when requesting code.",
"log_id": "202206221854370101130062072500FFA2"
}