Search API Connector Documentation

Print

Import TikTok Ads Data to Google Sheets

In this guide, we’ll walk through how to import TikTok Ads data directly into Google Sheets, using the API Connector add-on for Sheets.

The TikTok Ads API is quite strange in that it uses a non-standard implementation of the OAuth2 standard. Therefore we will get our token through some custom API requests rather than through API Connector’s automatic OAuth2 connection manager.

CONTENTS

BEFORE YOU BEGIN

Click here to install the API Connector add-on from the Google Marketplace.

PART 1: CREATE A TIKTOK APP

  1. Navigate to https://ads.tiktok.com/marketing_api/ and register for a new account.
    tiktok-ads-img1
  2. Once you’re logged in, click on My Apps in the top nav
    tiktok-ads-img2
  3. From the Apps screen, click Create New
    tiktok-ads-img3
  4. Set up your App, choosing the permissions you’d like access to:
    tiktok-ads-img4
  5. Your app will initially be in Pending status. Once it’s approved (should be a day or two), it will look like this. Click Edit to get your App ID and Secret, we’ll need those later.
    tiktok-ads-img5

PART 2: GET YOUR AUTH CODE

  1. Once your app has been approved, click on your app name from the apps dashboard
    tiktok-ads-img7
  2. Scroll down the page until you reach your authorized URL. Copy this to your clipboard.
    tiktok-ads-img8
  3. Paste this entire URL into a web browser
    tiktok-ads-img9
  4. You will see a modal prompting you to log in and accept whatever permissions you selected while creating your app. Click Confirm.
    tiktok-ads-img10
  5. On the next screen you’ll see a returned URL in your URL bar. We’re looking for the value in the ‘auth_code’ parameter, so grab that and keep it safe. It’s probably easiest to just copy and paste the entire URL into your clipboard so you can extract it from there.
    tiktok-ads-img11
  6. All right, we’re all set with our values. Let’s hop over to API Connector and get our access token.

PART 3: GET YOUR ACCESS TOKEN

Choose the POST method and enter this the request URL for an access token

https://ads.tiktok.com/open_api/v1.2/oauth2/access_token/

In the POST body, enter all the values we collected above, like this:

{
    "secret": "xxxxx", 
    "app_id": "xxxxx", 
    "auth_code": "xxxxx"
}

Substitute in your secret, app ID, and authorization code. Name your request and click Run . The whole thing should look like this:
tiktok-ads-img12

Congrats, you have your access token! This is what we’ll use for getting ad data.

PART 4: PULL LIST OF AD ACCOUNTS INTO SHEETS

Let’s first pull in a list of our ad accounts.

  1. In the Request screen, click Actions > Copy to copy the request we just made.
  2. Replace the original URL (ending with /oauth2/access_token/) with this new URL: https://ads.tiktok.com/open_api/oauth2/advertiser/get/
  3. Keep everything else the same and click Run. You’ll see a list of all the ad accounts that you have access to. (Note that Sheets automatically truncates the advertiser ID to 15 characters, so you’ll still need to get your full advertiser ID from the interface).
    tiktok-ads-img13

PART 5: GET TIKTOK AD DATA IN SHEETS

You can see a list of available endpoints in the docs.

As an example, choose the following options:

  • Method = GET
  • Request URL = https://ads.tiktok.com/open_api/v1.1/reports/ad/get/?advertiser_id=694230020xxxx&start_date=2021-02-01&end_date=2021-02-04&fields=["stat_cost","show_cnt","click_cost","ctr"]
  • Headers = Key: Access-Token, Value = <your access token>

The whole thing should look like this:
tiktok-ads-img14

If you would like to see your data grouped by campaign name instead of by date, edit your URL to include a group_by=["STAT_GROUP_BY_FIELD_ID"] parameter like this:
https://ads.tiktok.com/open_api/v1.1/reports/ad/get/?advertiser_id=6942300208919281666&start_date=2021-03-15&end_date=2021-03-25&fields=["campaign_name","campaign_id","stat_cost","show_cnt","click_cost","ctr"]&group_by=["STAT_GROUP_BY_FIELD_ID"]
tiktok-ads-img15

Leave a Comment