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:
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.
Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new
Next, login to your TikTok developer account and click on “My Apps“:
Click on “Create App ID” to create a new app:
Fill out the required information and click “Confirm” to submit your application:
After submitting your application, the status of the app will be shown as “Pending verification” (this takes at most one business day):
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:
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.
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:
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:
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.
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:
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.
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:
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:
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.
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:
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:
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:
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.
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:
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!
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: