> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mixpeek.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# TikTok

> Sync videos from a TikTok account into a Mixpeek bucket through the TikTok Content API.

<Note>
  Each video becomes a bucket object carrying its description, likes, views, shares, and comment count.
</Note>

## Overview

Mixpeek calls the official TikTok Content API as the authorized account. It syncs that account's videos, not arbitrary public ones.

## Prerequisites

* A TikTok Developer account with an approved app.
* The `user.info.basic` and `video.list` scopes granted during authorization.
* An OAuth authorization completed for the account you want to sync.

## Configuration

### Connection-level fields

| Field                          | Required | Description                                             |
| ------------------------------ | -------- | ------------------------------------------------------- |
| `credentials.client_key`       | Yes      | App Client Key from the TikTok Developer Portal         |
| `credentials.client_secret`    | Yes      | App Client Secret, encrypted at rest                    |
| `credentials.access_token`     | Yes      | Access token, valid for 24 hours                        |
| `credentials.refresh_token`    | Yes      | Used to mint a new access token, encrypted at rest      |
| `credentials.open_id`          | Yes      | The account's `open_id` from the authorization response |
| `credentials.token_expires_at` | No       | Access token expiry                                     |
| `scopes`                       | No       | Defaults to `["user.info.basic", "video.list"]`         |

### Sync-level fields

| Field                      | Required       | Description                                                   |
| -------------------------- | -------------- | ------------------------------------------------------------- |
| `source_path`              | Yes by the API | Ignored by this provider, which uses the authorized `open_id` |
| `polling_interval_seconds` | No             | Defaults to `300`                                             |

<Warning>
  The sync API requires `source_path`, and the TikTok provider does not read it. Pass `/` and select the account through `open_id` on the connection.
</Warning>

## Setup

<Steps>
  <Step title="Create and approve a TikTok app">
    1. Open the [TikTok Developer Portal](https://developers.tiktok.com).
    2. Create an app and request Login Kit plus Content Posting API access.
    3. Copy the **Client Key** and **Client Secret**.
    4. Add `user.info.basic` and `video.list` to the app's scopes.
  </Step>

  <Step title="Authorize the account">
    Run the TikTok Login Kit OAuth flow. The callback returns an access token, a refresh token, and the account's `open_id`.

    <Warning>
      Access tokens last 24 hours. Store the refresh token; Mixpeek uses it to renew.
    </Warning>
  </Step>

  <Step title="Create the storage connection">
    <CodeGroup>
      ```python Python theme={null}
      from mixpeek import Mixpeek

      client = Mixpeek(api_key="your-mixpeek-api-key")

      connection = client.organizations.connections.create(
          name="Brand TikTok Account",
          provider_type="tiktok",
          provider_config={
              "credentials": {
                  "type": "oauth",
                  "client_key": "your-client-key",
                  "client_secret": "your-client-secret",
                  "access_token": "your-access-token",
                  "refresh_token": "your-refresh-token",
                  "open_id": "your-open-id",
              },
          },
      )
      print(f"Created connection: {connection['connection_id']}")
      ```

      ```javascript JavaScript theme={null}
      import { Mixpeek } from 'mixpeek-sdk'

      const client = new Mixpeek({ apiKey: 'your-mixpeek-api-key' })

      const connection = await client.organizations.connections.create({
        name: 'Brand TikTok Account',
        provider_type: 'tiktok',
        provider_config: {
          credentials: {
            type: 'oauth',
            client_key: 'your-client-key',
            client_secret: 'your-client-secret',
            access_token: 'your-access-token',
            refresh_token: 'your-refresh-token',
            open_id: 'your-open-id',
          },
        },
      })
      console.log('Created connection:', connection.connection_id)
      ```

      ```bash cURL theme={null}
      curl -X POST https://api.mixpeek.com/v1/organizations/connections \
        -H "Authorization: Bearer YOUR_MIXPEEK_API_KEY" \
        -H "Content-Type: application/json" \
        -d '{
          "name": "Brand TikTok Account",
          "provider_type": "tiktok",
          "provider_config": {
            "credentials": {
              "type": "oauth",
              "client_key": "your-client-key",
              "client_secret": "your-client-secret",
              "access_token": "your-access-token",
              "refresh_token": "your-refresh-token",
              "open_id": "your-open-id"
            }
          }
        }'
      ```
    </CodeGroup>
  </Step>

  <Step title="Create the sync">
    ```bash cURL theme={null}
    curl -X POST https://api.mixpeek.com/v1/buckets/bkt_your_bucket_id/syncs \
      -H "Authorization: Bearer YOUR_MIXPEEK_API_KEY" \
      -H "X-Namespace: ns_your_namespace_id" \
      -H "Content-Type: application/json" \
      -d '{
        "connection_id": "conn_your_connection_id",
        "source_path": "/",
        "polling_interval_seconds": 3600
      }'
    ```
  </Step>
</Steps>

## Related

<CardGroup cols={2}>
  <Card title="Instagram" icon="instagram" href="/docs/integrations/social-media/instagram">
    The same account-scoped pattern on Instagram.
  </Card>

  <Card title="Social media overview" icon="share-nodes" href="/docs/integrations/social-media/overview">
    How social connectors map to buckets.
  </Card>
</CardGroup>
