The TikTok Business API SDK is a comprehensive suite of client libraries that can help our developers and partners to integrate with TikTok API for Business easily and faster in a standardized way. It is the ultimate solution for developers looking to streamline the integration process and enhance productivity. Our SDK, launching in phases, includes APIs for Authentication, Campaign Creation, Reporting, Business Center and more. For details, please refer to this page.
Java, Python and Javascript are among the most popular languages for TikTok business third-party developers. The TikTok Business API SDK is a code package that provides an interface between your application and Tiktok's business APIs for these three languages. This tutorial provides the basic knowledge needed to access to our SDK and includes sample code for your reference.
- API version: 1.0.1
- Create a TikTok For Business account
- Register as a developer
- Create a developer app
- Obtain authorization
- Obtain authentication
- Java 1.7+
- Maven
Option 1(recommended)
- Add the TikTok Business API SDK dependency to your project pom.xml file
<dependency> <groupId>io.github.jasonchentt</groupId> <artifactId>tiktok-business-api-sdk-official</artifactId> <version>1.0.1</version> </dependency>
- Run the following command to install the SDK
mvn install
- Import and use Java SDK method, below is the sample code for reference
import io.swagger.client.api.ToolApi; import business_api.Response;; public class ToolTest { public static void main(String[] args) { ToolApi apiInstance = new ToolApi(); String accessToken = "Your_accessToken_id"; String advertiserId = "Your_advertiser_id"; try { Response result = apiInstance.toolLanguage(advertiserId, accessToken); System.out.println(result); System.out.println("Success ToolApi#toolLanguage"); } catch (Exception e) { System.err.println("Exception when calling ToolApi#toolLanguage"); e.printStackTrace(); } } }
Option 2
-
Download the TikTok Business API SDK
git clone https://github.com/tiktok/tiktok-business-api-sdk.git
-
Set up your local environment
- Add this dependency to your project's POM and load the maven changes if you are using Maven, otherwise you could skip this step.
<dependency> <groupId>io.swagger</groupId> <artifactId>business_api_client</artifactId> <version>1.0.0</version> <scope>compile</scope> </dependency>
- Build the SDK jar file with following the commands
cd your_path/tiktok-business-api-sdk/java_sdk mvn install package
-
Manually import the JAR files
Note: If you are using IntelliJ, within your project, click on File-> Project Structure -> Modules and click the '+' to add the jar you built in the previous step.
-
Install the SDK package within your project
cd your project mvn install package
-
Run and test the SDK
- Create a class and import it to the location where you're able to run it. Below are the sample codes for your reference.
import io.swagger.client.api.ToolApi; import java.util.*; import static org.junit.Assert.*; import business_api.Response; public class Tool { ToolApi apiInstance; String accessToken = "Your_access_token"; String advertiserId = "Your_advertiser_id"; public Tool() { ToolApi instance = new ToolApi(); this.apiInstance = instance; } public void ToolLanguageTest() { try { Response result = apiInstance.toolLanguage(advertiserId, accessToken); assertNotNull(result); System.out.println(result); System.out.println("Success ToolApi#toolLanguage"); } catch (Exception e) { System.err.println("Exception when calling ToolApi#toolLanguage"); e.printStackTrace(); } } }
- Python 3.4+
Option 1(recommended)
- Download the TikTok Business API SDK within your project
pip install tiktok-business-api-sdk-official
- Import and use Python SDK method, below is the sample code for reference
from __future__ import print_function import business_api_client from business_api_client.rest import ApiException from pprint import pprint def test_tool_language(): # create an instance of the API class api_instance = business_api_client.ToolApi() advertiser_id = TEST_ADVERTISER_ID # str | access_token = TEST_ACCESS_TOKEN # str | try: api_response = api_instance.tool_language(advertiser_id, access_token) pprint(api_response) except ApiException as e: print("Exception when calling ToolApi->tool_language: %s\n" % e) test_tool_language()
Option 2
- Download the TikTok Business API SDK
git clone https://github.com/tiktok/tiktok-business-api-sdk.git
- Set up the Python virtual environment by using the following command. If you already have your own virtual environment, please skip this step and source into your own project.
python3 -m venv your_virtual_env source your_virtual_env/bin/activate
- Set Local env and install dependency with following commands
export PYTHONPATH=your_path/tiktok-business-api-sdk:your_path/tiktok-business-api-sdk/python_sdk:your_path/tiktok-business-api-sdk/python_sdk/business_api_client cd your_path/tiktok-business-api-sdk/python_sdk pip install -r requirements.txt python3 setup.py install
- Run and test the Python SDK. Below are the sample codes for your reference.
from __future__ import print_function import business_api_client from pprint import pprint TEST_ADVERTISER_ID = 'Your_advertiser_id' TEST_ACCESS_TOKEN = 'Your_access_token' def test_tool_language(): # create an instance of the API class api_instance = business_api_client.ToolApi() advertiser_id = TEST_ADVERTISER_ID # str | access_token = TEST_ACCESS_TOKEN # str | try: api_response = api_instance.tool_language(advertiser_id, access_token) pprint(api_response) except ApiException as e: print("Exception when calling ToolApi->tool_language: %s\n" % e)
- Javascript v13+, up to v18
- npm
Option 1(recommended)
- Download the TikTok Business API SDK within your project
npm install tiktok-business-api-sdk-official
- Import and use JavaScript SDK method, below is the sample code for reference
import * as js_sdk from "tiktok-business-api-sdk-official"; let api = new js_sdk.ToolApi() let advertiserId = "Your_advertiser_id"; let accessToken = "Your_accessToken_id"; let body = new js_sdk.AdvertiserUpdateBody(advertiserId); let opts = { 'body': body }; apiInstance.advertiserUpdate(accessToken, opts, (error, data, response) => { if (error) { console.error(error); } else { console.log('advertiserUpdate called successfully.'); } });
Option 2
-
Download the TikTok Business API SDK
git clone https://github.com/tiktok/tiktok-business-api-sdk.git
-
Set Local env and install the dependencies
- Install js-sdk dependencies
cd your_path/tiktok-business-api-sdk/js_sdk npm install
- In your project, run the following command
npm install your_path/tiktok-business-api-sdk/js_sdk --save
- In your project, add the following code in package.json to set js_sdk as module
{ ... "type": "module", ... }
-
Run and test JavaScript SDK
- Import the SDK to your JavaScript file and add the methods you would like to use. Below are the sample codes for your reference.
import * as js_sdk from "business_api_client" let api = new js_sdk.ToolApi() let advertiserId = "Your_advertiser_id"; let accessToken = "Your_accessToken_id"; api.toolLanguage(advertiserId, accessToken, (error, data, response) => { if (error) { console.error(error); } else { console.log('toolLanguage called successfully. Returned data: ' + JSON.stringify(data)); } });
- If you want to report bugs or issues, please visit TikTok API for Business Developer Portal and click "?" on the top right to submit a ticket under Marketing API category.
Here are the detailed documentation for currently supported programming languages.
- Java: please refer to java_sdk/README.md
- Python: please refer to python_sdk/README.md
- JavaScript: please refer js_sdk/README.md