← All articles & guides
Article · Tiktok

How to connect Tiktok account using API

The TikTok connection lives partly in your product and partly on TikTok's developer platform.

How to connect Tiktok account using API
Connecting TikTok · Integration Guide
Integration Guide
start
TUTORIALS / SOCIAL CONNECTIONS

Connecting TikTok to your app, start to finish

Every screen your user taps, every request your server makes, and every token you need to keep safe — laid out as one continuous path from an empty integrations page to a working TikTok connection.

Read time · 16 min Level · Intermediate You'll need · a backend server + HTTPS domain API version · TikTok v2
0

What you need before you open a single tab

prerequisites

The TikTok connection lives partly in your product and partly on TikTok's developer platform. Gather these first — most delays in this process come from missing one of them halfway through.

  • A TikTok account you're comfortable registering as a developer (personal or business).
  • A live HTTPS domain for your app — TikTok will not redirect to localhost or plain HTTP in production.
  • A backend that can make server-to-server requests and store secrets — the token exchange must never happen in the browser.
  • A clear answer to "what will this connection actually do?" — read a profile, list videos, or publish content. This decides which scopes you request.
  • A privacy policy and terms of service URL, both publicly reachable — required for app review later.
Don't request every scope "just in case."TikTok's review team checks that each permission matches a visible feature. Unused scopes slow down approval and widen your risk if a token ever leaks.
1

Register on TikTok for Developers

tiktok.com

Go to TikTok's developer portal and sign in with the account you decided on in step 0. Complete the developer profile — company name, category, and a contact email your team actually monitors, since app-review correspondence lands there.

Do use a shared team inbox.App review, policy notices, and rate-limit warnings all go to this address. A personal inbox becomes a single point of failure.
2

Create an app and collect your keys

client key · client secret

Inside the developer portal, create a new app. Give it the name your users will actually see on TikTok's authorization screen — this is customer-facing copy, not an internal codename. Once created, TikTok issues two values:

ValueLives wherePurpose
client_keyFrontend + backendIdentifies your app in the authorization URL
client_secretBackend onlyProves your server's identity when exchanging a code for a token
Don't ever ship the client secret to the browser or a mobile bundle.If it's readable in dev tools or a decompiled APK, treat it as compromised and rotate it immediately from the developer portal.
3

Add products and pick your scopes

Login Kit · Content Posting · Display

In the app dashboard, add the products that match the feature you scoped out in step 0. Each product unlocks a set of permission scopes you'll later request from the user.

user.info.basic user.info.profile video.list video.publish video.upload

A profile-display feature needs only user.info.basic. A scheduling feature that actually posts on the user's behalf needs video.publish, which sits behind a stricter review — plan for that lead time.

4

Register your redirect URI

exact match required

Set the URL on your server that TikTok will send users back to after they approve access — for example https://app.yourproduct.com/integrations/tiktok/callback. TikTok compares this value byte-for-byte against what your authorization request sends, including trailing slashes.

Don't leave a trailing slash mismatch./callback and /callback/ are different strings to TikTok's servers, and a mismatch fails silently with a generic redirect error.
5

Understand the full authorization handshake

workflow

Before writing any code, it helps to see the handshake as one loop. Six things happen, in this order, every time a user connects their TikTok account:

Two lanes, six stages — the browser and your server only ever exchange a short-lived code; the secret and the tokens stay server-to-server.

The detail worth remembering: the authorization code in stage 4 is not the access token. It's a one-time voucher, valid for a few minutes, that only your server can redeem — and only by presenting the client secret alongside it.

6

Send the user to TikTok

GET /v2/auth/authorize/

When someone clicks "Connect TikTok," redirect their browser to TikTok's authorization endpoint with your app's identifying details. Generate a fresh, random state value every time and save it against that user's session — you'll check it when they come back.

server.js
// 1. Create a random state and save it to the session
const state = crypto.randomUUID();
session.tiktokState = state;

// 2. Build the authorization URL
const params = new URLSearchParams({
  client_key: process.env.TIKTOK_CLIENT_KEY,
  scope: "user.info.basic,video.list",
  response_type: "code",
  redirect_uri: "https://app.yourproduct.com/integrations/tiktok/callback",
  state,
});

const authUrl = `https://www.tiktok.com/v2/auth/authorize/?${params}`;
// redirect the user's browser to authUrl
Do keep the scope list as short as step 3 decided.Every scope you add here reappears on TikTok's approval screen, in plain language, for the user to read.
7

Catch the redirect and check the state

your redirect URI

TikTok redirects back with ?code=...&state=... in the query string. Before doing anything else, compare the returned state against the one you saved in step 6.

routes/tiktok-callback.js
app.get("/integrations/tiktok/callback", async (req, res) => {
  const { code, state } = req.query;

  if (state !== session.tiktokState) {
    // stop here — this request did not originate from your own flow
    return res.status(400).send("State mismatch");
  }

  // safe to continue — move to the token exchange in step 8
});
Don't skip the state check "for now."Without it, an attacker can trick a logged-in user into linking the attacker's TikTok account to the victim's profile.
8

Trade the code for real tokens

POST /v2/oauth/token/

Still on your server, send the code to TikTok's token endpoint along with your client key and secret. This request must happen server-to-server — never from the user's browser.

services/tiktok.js
const response = await fetch("https://open.tiktokapis.com/v2/oauth/token/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: new URLSearchParams({
    client_key: process.env.TIKTOK_CLIENT_KEY,
    client_secret: process.env.TIKTOK_CLIENT_SECRET,
    code,
    grant_type: "authorization_code",
    redirect_uri: "https://app.yourproduct.com/integrations/tiktok/callback",
  }),
});

const tokens = await response.json();
// tokens.access_token   → short-lived, ~24 hours
// tokens.refresh_token  → long-lived, ~365 days
// tokens.open_id        → the TikTok user's stable ID
9

Store what you just received

database, not local storage

Save access_token, refresh_token, and the expiry timestamps against the connected user's row, encrypted at rest. This is the moment the connection becomes real from your product's point of view.

Do record both expiry times.Access tokens and refresh tokens expire on different schedules — track both so you know exactly when to refresh versus when to ask the user to reconnect.
Don't put tokens in browser local storage or a cookie readable by JavaScript.Anything a script on the page can read, a malicious script can also read. Keep tokens server-side and let the browser hold only a session reference.
10

Make your first authenticated call

GET /v2/user/info/

With a stored access token, your server can now speak for the connected account. A basic profile check is a good first call to confirm everything is wired correctly.

services/tiktok.js
const profile = await fetch("https://open.tiktokapis.com/v2/user/info/?fields=open_id,display_name,avatar_url", {
  headers: { Authorization: `Bearer ${accessToken}` },
});

A successful response returns the fields you asked for under data.user. Show a piece of it back to your user immediately — their name or avatar — so the connection feels confirmed rather than invisible.

11

Refresh tokens before they expire

POST /v2/oauth/token/

Access tokens are short-lived on purpose. Run a background job that checks for tokens expiring soon and refreshes them proactively, rather than waiting for an API call to fail.

jobs/refresh-tiktok-tokens.js
const refreshed = await fetch("https://open.tiktokapis.com/v2/oauth/token/", {
  method: "POST",
  headers: { "Content-Type": "application/x-www-form-urlencoded" },
  body: new URLSearchParams({
    client_key: process.env.TIKTOK_CLIENT_KEY,
    client_secret: process.env.TIKTOK_CLIENT_SECRET,
    grant_type: "refresh_token",
    refresh_token: storedRefreshToken,
  }),
});
Don't wait for a 401 in production traffic to trigger a refresh.That turns an invisible maintenance task into a user-facing failure at an unpredictable moment.
12

Plan for the responses you don't want

error handling

A production integration spends more time handling the edge cases below than the happy path above.

401
Access token expired or invalidAttempt one refresh using the stored refresh token; if that also fails, mark the connection as needing reauthorization and prompt the user.
429
Too many requestsBack off using the retry delay TikTok returns rather than a fixed interval, and batch calls where the API allows it.
10004
Refresh token expiredThis happens after long inactivity — around a year. There is no recovery except asking the user to reconnect from scratch.
10011
Scope not authorizedThe account never granted this permission, or it was revoked from TikTok's own settings. Re-run the authorization flow with the scope explicitly listed.
13

Test with sandbox users first

before requesting review

Add your own account and a few teammates as sandbox testers in the developer portal. Run the entire loop — connect, call the API, disconnect, reconnect — before asking anyone outside your team to try it.

  • Connecting works on a fresh account with no prior authorization.
  • Disconnecting on TikTok's side (revoking access) is detected and handled the next time you call the API.
  • Denying the permission screen returns the user to a clear, non-broken state in your app.
  • Refreshing a token works without the user noticing anything happened.
14

Submit your app for review

required for restricted scopes

Scopes like video.publish stay restricted to your sandbox testers until TikTok reviews your app. Prepare a short screen recording of the real feature in use, a working privacy policy link, and a plain description of why each requested scope is needed.

Do show the actual connect flow in your demo video.Reviewers approve faster when they can see the permission screen, the scope list, and the resulting feature in one continuous recording.
15

Go live

the last step

Once approved, switch any sandbox-only configuration to production values, confirm your redirect URI points at your live domain, and remove test-only accounts from the sandbox tester list. From here, monitor connection health the same way you'd monitor any other critical dependency.

The short version

Sixteen steps compress into two habits: keep secrets server-side, and never trust a redirect without checking its state.

Do

  • Validate state on every callback
  • Keep client_secret on the server only
  • Request the smallest scope set the feature needs
  • Refresh tokens proactively, on a schedule
  • Show the user something real right after connecting

Don't

  • Store tokens in local storage or client-readable cookies
  • Skip sandbox testing before requesting review
  • Retry a 429 on a fixed interval
  • Assume a refresh token lasts forever
  • Reuse one redirect URI across environments
Guides · Social Connections · TikTok API v2