How to import TikTok ads and marketing data into Google Sheets

TikTok is currently the world’s fastest growing social media platform.

In this tutorial, we’ll show you how to connect the TikTok API to Google Sheets in 7 steps:

  1. Install the Apipheny add-on
  2. Create a TikTok API app
  3. Get your TikTok authorization URL
  4. Direct advertisers to access the Authorization URL
  5. Obtain an Access Token
  6. Choose a TikTok API endpoint
  7. Enter and run your TikTok API request in Apipheny

Step 1.) Install and open the Apipheny add-on for Google Sheets

Apipheny is an API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to unlimited API data sources, make unlimited API requests, and more. There is a 30 day free trial included.

1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install

2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.

In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.

open apipheny

Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new

Step 2.) Create a TikTok API app and obtain an App ID

Next, login to your TikTok developer account and click on “My Apps“:

Log in to your TikTok developer account and click "My Apps"
Log in to your TikTok developer account and click “My Apps”

Click on “Create App ID” to create a new app:

Click "Create API ID" after clicking on "My Apps"
Click “Create API ID” after clicking on “My Apps”

Fill out the required information and click “Confirm” to submit your application:

Enter the App ID details and then click "Confirm"
Enter the App ID details and then click “Confirm”

After submitting your application, the status of the app will be shown as “Pending verification” (this takes at most one business day):

The status of your TikTok API app will be "Pending verification" until verified
The status of your TikTok API app will be “Pending verification” until verified

Once approved, the status then changes to “Approved”.

Once approved, you’ll see your app’s ID, secret key, and authorization link in the “My Apps” dashboard:

Verified TikTok API app with the App ID and Secret
Verified TikTok API app with the App ID and Secret

You have now successfully a TikTok API app and obtained your App ID.

Copy and paste the values for your App ID and App Secret somewhere safe because you will need them in the next steps.

Step 3.) Get a TikTok authorization URL

In the My Apps dashboard, click on your app to access the app’s settings page.

Scroll down until you find the Authorized URL, then copy and paste it somewhere safe because you will need it in the next steps:

In your app's settings, copy your Authorized URL somewhere safe
In your app’s settings, copy your Authorized URL somewhere safe

Step 4.) Direct advertisers to access the Authorization URL to complete the Authorization

Once you’ve copied your authorization URL, you’ll need to send it to your TikTok advertising client, who will then need to access it in their browser. If you are the TikTok advertiser, you can copy and paste the authorization URL in your browser window.

When you visit the URL, you/the advertiser will be prompted to log in to your TikTok Ads account.

The browser will then redirect and display a dedicated authorization page, like so:

This is the page you see when you visit the TikTok authorization URL, you'll be prompted to log in to your TikTok ads account and give permissions to the TikTok API App your created in the previous step
This is the page you see when you visit the TikTok authorization URL, you’ll be prompted to log in to your TikTok ads account and give permissions to the TikTok API App your created in the previous step

When you/the advertiser clicks on Confirm, the page will then redirect to the callback address, where you’ll see auth_code and state as parameter values in the URL:

From the URL, copy and paste the auth_code value to a safe place because you will need it in the next steps.

Step 5.) Obtain a long-term Access Token

Next you need to get a long term access token for the TikTok APi.

Open up a command prompt window (for Windows OS) or a terminal (for Mac OS) and run the following command:

curl -H "Content-Type:application/json" -X POST -d "{\"secret\": \"APP SECRET\", \"app_id\": \"APP ID\", \"auth_code\": \"AUTH_CODE\"}" https://ads.tiktok.com/open_api/oauth2/access_token_v2/

Don’t forget to replace the values (APP SECRET, APP ID, and AUTH_CODE) with the values you got in the previous steps.

Note: For Mac OS you may need to use single quotes ( ' ) instead of double quotes ( " ).

Your access token will then be displayed in the response:

Getting a long term access token for the TikTok API by running a console command

Copy and paste your access token value to a safe location because you will need it in the next steps.

Note: If the token/key that you generate has an expiration time, you will need to complete this same process again to get a new token when the old one expires.

Step 6.) Choose a TikTok API endpoint

In this section, we’ll show you how to browse the TikTok API documentation to find an API endpoint URL that retrieves the information you need from your TikTok account.

If you already know your TikTok API URL, or you want to use the same example URL/endpoint as us, just skip to Step 7.

To browse a list of available TikTok API endpoints, first open the TikTok API documentation page: https://ads.tiktok.com/marketing_api/docs?id=100509

The menu on the left contains a list of categories for the TikTok API endpoints:

TikTok API documentation
TikTok API documentation

An example endpoint is the Getting creative materials, from the Ads category, which returns an automated ad’s creative materials, including call-to-actions, texts, ad names, images, and/or videos.

The API URL for this endpoint is:

https://business-api.tiktok.com/open_api/v1.2/ad/dynamic/get/

The documentation for each endpoint contains a paragraph describing the endpoint’s purpose, the HTTP method used (GET), the full URL, and a table describing the required/optional headers and parameters for the endpoint:

TikTok API endpoint documentation example
TikTok API endpoint documentation example

All API calls to TikTok Marketing API should be made to the https://business-api.tiktok.com/open_api/v1.2/ base domain.

TikTok API root/base URL:

https://business-api.tiktok.com/open_api/v1.3/

All endpoints should be appended to this base URL.

Note: Check their documentation to confirm the latest version and update the version number in the URL if necessary.

More TikTok API endpoint examples

The Get campaigns endpoint, which gets all campaigns for an ad account:

Method: GET
API URL Path: https://business-api.tiktok.com/open_api/v1.3/campaign/get/
Headers:
    Header 1 Key:
       Access-Token
    Header 1 Value:
       your_token

Make sure to replace your_token with the token you previously obtained.


The Download leads endpoint, which downloads leads through this endpoint when the task state is SUCCEED. You need to create a download task through the /page/lead/task/ endpoint and poll it first.

Method: GET
API URL Path: https://business-api.tiktok.com/open_api/v1.3/page/lead/task/download/
Headers:
    Header 1 Key:
       Access-Token
    Header 1 Value:
       your_token

Make sure to replace your_token with the token you previously obtained.


The Get ads endpoint, which get ad data of regular ads and automated creative ads:

Method: GET
API URL Path: https://business-api.tiktok.com/open_api/v1.3/ad/get/
Headers:
    Header 1 Key:
       Access-Token
    Header 1 Value:
       your_token

Make sure to replace your_token with the token you previously obtained.


The Get feed endpoint, which gets a particular feed or all feeds for a catalog:

Method: GET
API URL Path: https://business-api.tiktok.com/open_api/v1.3/catalog/feed/get/
Headers:
    Header 1 Key:
       Access-Token
    Header 1 Value:
       your_token

Make sure to replace your_token with the token you previously obtained.


The Get all audiences endpoint, which gets a list of all audiences. The returned list is paginated with a maximum paging size of 100.

Method: GET
API URL Path: https://business-api.tiktok.com/open_api/v1.3/dmp/custom_audience/list/?advertiser_id=ADVERTISER_ID&page=PAGE&page_size=PAGE_SIZE
Headers:
    Header 1 Key:
       Access-Token
    Header 1 Value:
       your_token

Make sure to replace:

  • your_token with the token you previously obtained;
  • ADVERTISER_ID with a real advertiser id;
  • PAGE with a page number;
  • PAGE_SIZE with the number of records you want per page (maximum 100 records)

The Update video name endpoint, which updates the name of a video:

Method: POST
API URL Path: https://business-api.tiktok.com/open_api/v1.3/file/video/ad/update/
Headers:
    Header 1 Key:
       Access-Token
    Header 1 Value:
       your_token
POST Body:
{
    "advertiser_id": "ADVERTISER_ID",
    "file_name": "FILE_NAME",
    "video_id": "VIDEO_ID"
}

Make sure to replace:

  • your_token with the token you previously obtained;
  • ADVERTISER_ID with a real advertiser id;
  • FILE_NAME with a name for your video file;
  • VIDEO_ID with the video id corresponding to your file.

Tiktok API pagination

Pagination is a process that is used to divide a large dataset into smaller chunks (pages). Usually the endpoints that return a list of resources support pagination. 

Some of the TikTok API endpoints use the pagination option. This means you need to add some of these parameters at the end of the URL:

  • page – the number of the page you want to obtain;
  • page_size – the number of records per page;
  • cursor – cursor for pagination. If response.data.has_more is true, pass the response.data.cursor in this parameter in the subsequent request to receive the next page of results.
  • max_count – the maximum number of records that will be returned for each page.

Each endpoint that needs pagination will have in its documentation relevant information on which of these parameters you can use and how to do it.

Example:
https://business-api.tiktok.com/open_api/v1.3/adgroup/get/?page=2&page_size=150

In the example above, the data set will be divided in sets of 150 records per page, and only the second page (page number 2) will be displayed in Google Sheets.

Step 7.) Enter your TikTok API request into the Apipheny add-on

Now, to get your TikTok data in your Google Sheet, go back to your Google Sheet and make sure that you’ve installed the Apipheny add-on and you have it opened to the Import tab.

With the Import Tab open, enter the following details into the Apipheny add-on:

Method: At the top of the Apipheny add-on, select the HTTP method (eg. GET or POST) required by your TikTok API endpoint. For this example, we are using the “GET” method.

API URL: In Step 6, we explained how you can find the TikTok API endpoint that you need. Now copy your complete TikTok API URL into the Apipheny add-on, in the field that says API URL Path (JSON / CSV), followed by any GET parameters required for your query (if applicable).

For this example, we are using the User Information endpoint that returns authorized user information granted to a developer App. The corresponding URL for this endpoint is:

https://business-api.tiktok.com/open_api/v1.3/user/info/

If you’re following the same example as us, you can copy and paste this API URL into the Apipheny add-on. Or you can use one of the other URLs/endpoints we covered above.

Headers: In the Headers section of the Apipheny add-on, add one row with the following key and value:

Header
Key:
Access-Token
Value:
your_token

Replace your_token with the value of the token you generated previously, in Step 5.

Here’s what your TikTok API request should look like when entered into the Apipheny add-on:

TikTok API request entered in the Apipheny add-on

Step 8.) Import your TikTok data in your Google Sheet

The last step is to click the Run button at the bottom of the Apipheny add-on and then your TikTok data will be imported into your Google Sheets, congratulations!

TikTok API connected with Google Sheets and TikTok data imported into Google Sheets using the Apipheny add-on

That’s it! That’s how you can connect the TikTok API with Google Sheets API using the Apipheny add-on.

After making a successful request to the TikTok API, try querying a different TiKTok API endpoint, or try using one of the more advanced features in the Apipheny add-on.



Crypto API Tutorials:


API Tutorials


API Knowledge

What is an API?

What is an API URL?

What are parameters?

What is an endpoint?

What is an API key/token?

What is basic authentication?

What are headers?

What is a GET request?

What is a POST request?