Skip to content
Last updated

Tiktok Marketing API Export Integration

TikTok is a global social networking service that focuses on short-form videos and reports having 1 billion active monthly users around the globe. You can use TikTok's Marketing API to target customers by creating custom segments.

Treasure Data's TikTok Integration allows you to send job results from Treasure Data directly to TikTok Marketing using custom audiences.

What can you do with this Integration?

  • Send audience segments to TikTok to build the best-fit campaign to retarget existing customers and attract more look-alike audiences.
  • Stop targeting when end-users explicitly give opt-out consent.

Prerequisites

Requirements and Limitations

  • The maximum file size to be uploaded is 50MB per file and 500 files per audience, which means we only support uploading a maximum of 50MB * 500 files = 25000 MB ~ 25GB. Due to the plugin's restriction, the actual size is around 20GB.
  • After creating an audience, the audience will be accessible within one hour.
  • There is a maximum of 400 custom audiences.
  • Data before hashing needs to be in all uppercase or lowercase.
  • A minimum audience size of 1,000 is required to target custom audiences in an ad group.
  • The audience size will update within 24-48 hours on the Audiences page in TikTok's Ads Manager.
  • If you use OAuth authentication method, because of API Quotas on Tiktok OAuth Application, you might get the Quota warnings. Some delay would be expected while the connector will automatically retry after a certain duration to continue the job.
  • If you use token-based authentication method, please contact your TikTok representative to whitelisting certain API access (such as Streaming API).

Use the TD Console to Create Your Connection

Create a New Connection

In Treasure Data, you must create and configure the data connection prior to running your query. As part of the data connection, you provide authentication to access the integration.

  1. Open TD Console.
  2. Navigate to Integrations Hub > Catalog.
  3. Search for and select TikTok.

  1. Select Create Authentication.
  2. Select Authentication Mode

Recommendation: Use the OAuth Flow We strongly recommend using the OAuth flow for the following reasons:

  1. Simplicity and Convenience: The OAuth flow is designed to be user-friendly, allowing you to authorize your TikTok Ads account quickly and easily without the need to manage developer credentials.
  2. Security: OAuth is a secure industry standard for authorization. It ensures that your credentials are protected, reducing the risk of exposing sensitive information.
  3. Maintenance-Free: By using OAuth, you avoid the need for ongoing maintenance and updates that come with managing your own developer app. TreasureData will handle all the complexities, letting you focus on your marketing campaigns.
  4. Time-Saving and Less Error-Prone: Creating a developer account and then developing an app to obtain an access token is a time-consuming process. It involves multiple steps, including setting up the app, managing keys, and ensuring compliance with TikTok's policies, which can be error-prone and tedious.

Select Oauth as Authentication Mode

  • Log into your TikTok account in the browser (if you haven’t logged in previously) and grant permissions to Treasure Data - TikTok Data Connector by select Confirm

  • After Confirmation, you're redirected back Catalog page. Select Tiktok, and you can select Continue with your newly created Oauth connection.

Select Access Token - Authentication Mode

  • Type the access token to authenticate and select Continue.
    • To create a Tiktok Access Token, please refer to this guide HERE.

  1. Type a name for your New connection.
  2. Select Done.

Define your Query

Your query requires the id column.

  1. Complete the instructions for creating a destination integration.

  2. Navigate to Data Workbench > Queries.

  3. Select a query for which you would like to export data.

  4. Run the query to validate the result set.

  5. Select Export Results.

  6. Select an existing integration authentication.

  7. Define any additional Export Results details. In your export integration content, review the integration parameters.

For example, your Export Results screen might be different, or you might not have additional details to complete.

  1. Select Done.
  2. Run your query.
  3. Validate that your data moved to the destination you specified.

Integration Parameters for TikTok

ParameterTypes Description
auth_methodEnum:
  • oauth
  • access_token
This connector support two Authentication methods: - OAuth authentication - User can input access_token directly in UI - Required to create your own Tiktok App. Please refer HERE.
access_tokenStringFor Access Token mode only.
use_sandboxbooleanFor Access Token mode only. Flag to indicate that you are trying to push the segment to the sandbox environment of TikTok.
api_modeEnum, supported values: - CUSTOMER_FILE - STREAMINGSupported TikTok API mode.
  • Recommendation: Use the Streaming API We strongly recommend using the Streaming API for the following reasons:
    1. Real-Time Data Updates: The Streaming API allows for real-time data updates, ensuring your customer data is always current. This is crucial for activating audiences and launching campaigns with the most up-to-date information.
    2. Better Throughput for High Volume Data: If you handle large volumes of data, the Streaming API offers better throughput, making it more efficient and reliable for high-volume data synchronization.
    3. Future-Proofing: TikTok plans to deprecate the Customer File API. By choosing the Streaming API now, you avoid the need for future migrations, saving you time and effort down the line.
advertiser_idStringYour advertiser's id on TikTok.
audience_nameStringAudience's name. Note: This configuration key is used for CUSTOMER_FILE mode only.
encryption_typeEnum (FIRST_SHA256, FIRST_MD5, EMAIL_SHA256, PHONE_SHA256, IDFA_SHA256, IDFA_MD5, GAID_SHA256, GAID_MD5)ID Type. Note: This configuration key is used for CUSTOMER_FILE mode only.
audience_actionEnum
  • APPEND
  • REMOVE,
  • REPLACE
Audience's Action (REMOVE, REPLACE, ADD). Note: This configuration key is used for CUSTOMER_FILE mode only.
streaming_actionEnum, supported values:
  • ADD
  • DELETE
  • DELETE_AUDIENCE
Streaming export mode and the default value is ADD. Note: This configuration key is used for STREAMING mode only.
audience_namesStringList of segment audience names separated by comma. Note: This configuration key is used for STREAMING mode only.
audience_idsStringList of audience IDs separated by comma. Note: This configuration key is used for STREAMING mode only.
skip_invalid_recordboolean
  • true: Skip the invalid record and continue the job
  • false: Stop job when processing invalid record
thread_countIntegerConfigurable parallel request to TikTok. The default value is 5. Note: This configuration key is used for STREAMING mode only.

Example Query

The CUSTOMER_FILE mode, it supports only one column/alias with name id

SELECT id
FROM my_table

The Streaming mode can support multiple columns/alias: email, email_sha256, phone, phone_sha256, idfa, idfa_md5, idfa_sha256, aaid, aaid_md5, aaid_sha256

SELECT email, phone, idfa, aaid
FROM my_table

(Optional) Schedule Query Export Jobs

You can use Scheduled Jobs with Result Export to periodically write the output result to a target destination that you specify.

Treasure Data's scheduler feature supports periodic query execution to achieve high availability.

When two specifications provide conflicting schedule specifications, the specification requesting to execute more often is followed while the other schedule specification is ignored.

For example, if the cron schedule is '0 0 1 * 1', then the 'day of month' specification and 'day of week' are discordant because the former specification requires it to run every first day of each month at midnight (00:00), while the latter specification requires it to run every Monday at midnight (00:00). The latter specification is followed.

Scheduling your Job Using TD Console

  1. Navigate to Data Workbench > Queries

  2. Create a new query or select an existing query.

  3. Next to Schedule, select None.

  4. In the drop-down, select one of the following schedule options:

    Drop-down ValueDescription
    Custom cron...Review Custom cron... details.
    @daily (midnight)Run once a day at midnight (00:00 am) in the specified time zone.
    @hourly (:00)Run every hour at 00 minutes.
    NoneNo schedule.

Custom cron... Details

Cron ValueDescription
0 * * * *Run once an hour.
0 0 * * *Run once a day at midnight.
0 0 1 * *Run once a month at midnight on the morning of the first day of the month.
""Create a job that has no scheduled run time.
 *    *    *    *    *
 -    -    -    -    -
 |    |    |    |    |
 |    |    |    |    +----- day of week (0 - 6) (Sunday=0)
 |    |    |    +---------- month (1 - 12)
 |    |    +--------------- day of month (1 - 31)
 |    +-------------------- hour (0 - 23)
 +------------------------- min (0 - 59)

The following named entries can be used:

  • Day of Week: sun, mon, tue, wed, thu, fri, sat.
  • Month: jan, feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec.

A single space is required between each field. The values for each field can be composed of:

Field ValueExampleExample Description
A single value, within the limits displayed above for each field.
A wildcard '*' to indicate no restriction based on the field.'0 0 1 * *'Configures the schedule to run at midnight (00:00) on the first day of each month.
A range '2-5', indicating the range of accepted values for the field.'0 0 1-10 * *'Configures the schedule to run at midnight (00:00) on the first 10 days of each month.
A list of comma-separated values '2,3,4,5', indicating the list of accepted values for the field.0 0 1,11,21 * *'Configures the schedule to run at midnight (00:00) every 1st, 11th, and 21st day of each month.
A periodicity indicator '*/5' to express how often based on the field's valid range of values a schedule is allowed to run.'30 */2 1 * *'Configures the schedule to run on the 1st of every month, every 2 hours starting at 00:30. '0 0 */5 * *' configures the schedule to run at midnight (00:00) every 5 days starting on the 5th of each month.
A comma-separated list of any of the above except the '*' wildcard is also supported '2,*/5,8-10'.'0 0 5,*/10,25 * *'Configures the schedule to run at midnight (00:00) every 5th, 10th, 20th, and 25th day of each month.
  1. (Optional) You can delay the start time of a query by enabling the Delay execution.

Execute the Query

Save the query with a name and run, or just run the query. Upon successful completion of the query, the query result is automatically exported to the specified destination.

Scheduled jobs that continuously fail due to configuration errors may be disabled on the system side after several notifications.

(Optional) You can delay the start time of a query by enabling the Delay execution.

Activate a Segment in Audience Studio

You can also send segment data to the target platform by creating an activation in the Audience Studio.

  1. Navigate to Audience Studio.
  2. Select a parent segment.
  3. Open the target segment, right-mouse click, and then select Create Activation.
  4. In the Details panel, enter an Activation name and configure the activation according to the previous section on Configuration Parameters.
  5. Customize the activation output in the Output Mapping panel.

  • Attribute Columns
    • Select Export All Columns to export all columns without making any changes.
    • Select + Add Columns to add specific columns for the export. The Output Column Name pre-populates with the same Source column name. You can update the Output Column Name. Continue to select + Add Columnsto add new columns for your activation output.
  • String Builder
    • + Add string to create strings for export. Select from the following values:
      • String: Choose any value; use text to create a custom value.
      • Timestamp: The date and time of the export.
      • Segment Id: The segment ID number.
      • Segment Name: The segment name.
      • Audience Id: The parent segment number.
  1. Set a Schedule.

  • Select the values to define your schedule and optionally include email notifications.
  1. Select Create.

If you need to create an activation for a batch journey, review Creating a Batch Journey Activation.

Example TD CLI

td query \
  -d my_database \
  -r '{
    "accessToken": "__SAVED__",
    "useSandbox": true,
    "advertiserId": "12345678901234567890",
    "apiVersion": "v1.2",
    "audienceAction": "REPLACE",
    "audienceName": "test",
    "encryptionType": "FIRST_NORMAL"
  }' \
  "SELECT id FROM my_table" \
  -T presto