# TikTok Business API Setup Guide

This guide provides step-by-step instructions for setting up TikTok Business API integration for managing ad comments.

---

## Table of Contents

1. [Overview](#overview)
2. [Prerequisites](#prerequisites)
3. [TikTok Business Center Setup](#tiktok-business-center-setup)
4. [Environment Configuration](#environment-configuration)
5. [OAuth Redirect URI Configuration](#oauth-redirect-uri-configuration)
6. [Permissions & Scopes](#permissions--scopes)
7. [Development vs Production](#development-vs-production)
8. [Troubleshooting](#troubleshooting)

---

## Overview

**API Version:** Business API v1.3
**Base URL:** `https://business-api.tiktok.com/open_api/v1.3/`
**Auth Portal:** `https://business-api.tiktok.com/portal/auth`
**Token Endpoint:** `oauth2/access_token/`

### Features Supported
- Fetch advertisements (which act as "content")
- Read comments on advertisements
- Reply to ad comments

### ⚠️ Critical Limitations

> **Important:** This implementation **only supports Ad Comments (Paid Ads)**. TikTok's API does **NOT** support organic video comment management. You cannot:
> - Fetch comments on regular TikTok videos
> - Reply to organic video comments
> - Manage comments on non-ad content

This is a TikTok API limitation, not an application limitation.

---

## Prerequisites

- A TikTok account with access to [TikTok Business Center](https://business.tiktok.com/)
- Admin or Analyst access to a TikTok Ad Account
- An approved TikTok App in Business Center

---

## TikTok Business Center Setup

### Step 1: Access TikTok Business Center

1. Navigate to [TikTok Business Center](https://business.tiktok.com/)
2. Sign in with your TikTok account
3. If you don't have a Business Center, create one

> ⚠️ **Note:** This is **NOT** the same as the "TikTok for Developers" portal used for the Display API. You must use the Business Center.

### Step 2: Create or Access Your App

1. Go to **User Center** (top right) → **App Management** → **My Apps**
2. If you don't have an app, click **"Create App"**
3. Fill in the required details:
   - **App Name:** Your application name
   - **App Description:** Describe your use case
   - **Category:** Select "Business Tools" or similar
4. Submit for approval

### Step 3: Get App Credentials

Once your app is created/approved:

1. Go to **User Center** → **App Management** → **My Apps**
2. Select your app
3. Find the credentials:
   - **App ID** → This is your `TIKTOK_CLIENT_KEY`
   - **App Secret** → Click "View" to reveal → This is your `TIKTOK_CLIENT_SECRET`

> ⚠️ **Important:** Store these credentials securely. The App Secret is only shown once.
