### Install SDK Dependencies and Setup Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/README.md Sets up the Python environment by exporting PYTHONPATH, navigating to the SDK directory, installing requirements, and installing the SDK locally. ```bash 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 ``` -------------------------------- ### Create Campaign and ACO Ad (Python SDK) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/README.md Provides a comprehensive example of creating a TikTok advertising campaign and an ACO (App Campaign Optimization) ad using the SDK. It covers campaign creation, ad group setup, and media asset configuration. ```python from __future__ import print_function import business_api_client from business_api_client.rest import ApiException # Create instances of API classes campaign_instance = business_api_client.CampaignCreationApi() ad_aco_instance = business_api_client.AdAcoApi() # Replace with actual credentials and IDs ACCESS_TOKEN = "YOUR_ACCESS_TOKEN" ADVERTISER_ID = "YOUR_ADVERTISER_ID" ADGROUP_ID = "YOUR_ADGROUP_ID" def create_campaign_and_aco_ad(): # Create Campaign campaign_body = business_api_client.CampaignCreateBody( advertiser_id=ADVERTISER_ID, campaign_name="SDK-Campaign", objective_type="APP_PROMOTION", budget=50.0, budget_mode="BUDGET_MODE_TOTAL", app_promotion_type="APP_INSTALL" ) try: campaign_response = campaign_instance.campaign_create(ACCESS_TOKEN, body=campaign_body) print("Campaign Created:", campaign_response) campaign_id = campaign_response["data"]["campaign_id"] except ApiException as e: print("Exception when calling CampaignCreationApi->campaign_create:", e) # Create ACO Ad common_material = business_api_client.AdAcoBodyCommonMaterial( creative_authorized=True, call_to_action_id="CALL_TO_ACTION_ID", identity_type="CUSTOMIZED_USER", identity_id="IDENTITY_ID", ) media_info = business_api_client.AdAcoBodyMediaInfo( image_info=[business_api_client.AdAcoBodyMediaInfoImageInfo(web_uri="IMAGE_URI")], video_info=business_api_client.AdAcoBodyMediaInfoVideoInfo( video_id="VIDEO_ID", file_name="VIDEO_FILE_NAME" ), ) media_info_list = [business_api_client.AdAcoBodyMediaInfoList(media_info=media_info)] title_list = [business_api_client.AdAcoBodyTitleList(title="Sample Title")] display_name_list = [business_api_client.AdAcoBodyDisplayNameList(app_name="Sample App")] deeplink_list = [ business_api_client.AdAcoBodyDeeplinkList(deeplink="https://www.example.com", deeplink_type="NORMAL") ] body = business_api_client.AdAcoBody( advertiser_id=ADVERTISER_ID, adgroup_id=ADGROUP_ID, common_material=common_material, media_info_list=media_info_list, title_list=title_list, display_name_list=display_name_list, deeplink_list=deeplink_list ) try: ad_response = ad_aco_instance.ad_aco_create(ACCESS_TOKEN, body=body) print("ACO Ad Created:", ad_response) except ApiException as e: print("Exception when calling AdAcoApi->ad_aco_create:", e) # Call the function to execute the process # create_campaign_and_aco_ad() ``` -------------------------------- ### Python Ad Create Example Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/AdApi.md Example demonstrating how to use the AdApi's ad_create method to upload ad creatives and create an ad. It includes setup, API call, and error handling. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.AdApi() access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). body = business_api_client.AdCreateBody() # AdCreateBody | Ad create body parameters (optional) try: # Upload your ad creatives (pictures, videos, texts, call-to-action) and create an ad. For different placements, the creative formats and requirements are different. Upload your ad creatives according to the placement requirements. Each ad group can have up to 20 ads. See here to learn about how to create ads. [Ad create](https://ads.tiktok.com/marketing_api/docs?id=1739953377508354) api_response = api_instance.ad_create(access_token, body=body) pprint(api_response) except ApiException as e: print("Exception when calling AdApi->ad_create: %s\n" % e) ``` -------------------------------- ### Install TikTok Business API SDK (Python) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/README.md Installs the official TikTok Business API SDK for Python using pip. This is the recommended method for integrating the SDK into your project. ```bash pip install tiktok-business-api-sdk-official ``` -------------------------------- ### Setup Python Virtual Environment Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/README.md Commands to create and activate a Python virtual environment. This isolates project dependencies and is a best practice for Python development. ```bash python3 -m venv your_virtual_env source your_virtual_env/bin/activate ``` -------------------------------- ### Get TikTok Catalog Overview Example Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/CatalogApi.md Python example demonstrating how to retrieve the number of products in different audit statuses for a given catalog using the TikTok Business API SDK. It shows how to instantiate the API client and call the catalog_overview method. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.CatalogApi() catalog_id = 'catalog_id_example' # str | bc_id = 'bc_id_example' # str | access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). try: # Get the number of products in different audit statuses in a catalog. [Catalog Overview](https://business-api.tiktok.com/portal/docs?id=1740492470201345) api_response = api_instance.catalog_overview(catalog_id, bc_id, access_token) pprint(api_response) except ApiException as e: print("Exception when calling CatalogApi->catalog_overview: %s\n" % e) ``` -------------------------------- ### Python Ad Get Example Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/AdApi.md Example demonstrating how to use the AdApi's ad_get method to retrieve data for regular ads and ACO ads. It shows parameter usage for filtering and pagination. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.AdApi() advertiser_id = 'advertiser_id_example' # str | Advertiser ID access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). filtering = business_api_client.AdGetFilter() # AdGetFilter | Filter conditions (optional) page = 1 # int | Page number (optional) page_size = 10 # int | Number of items per page (optional) fields = ['campaign_id', 'ad_name'] # list[str] | Fields to retrieve (optional) try: # Get the data of regular ads and ACO ads. [Ad get](https://ads.tiktok.com/marketing_api/docs?id=1735735588640770) api_response = api_instance.ad_get(advertiser_id, access_token, filtering=filtering, page=page, page_size=page_size, fields=fields) pprint(api_response) except ApiException as e: print("Exception when calling AdApi->ad_get: %s\n" % e) ``` -------------------------------- ### Python SDK: Example Usage of term_get Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/AccountManagementApi.md Example Python code demonstrating how to use the `term_get` method from the TikTok Business API SDK. It shows how to instantiate the client, call the method with required parameters, and handle potential API exceptions. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.AccountManagementApi() advertiser_id = 'advertiser_id_example' # str | term_type = 'term_type_example' # str | access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). lang = 'EN' # str | (optional) (default to EN) try: # Get Terms. [Term Get](https://business-api.tiktok.com/portal/docs?id=1737191909315585) api_response = api_instance.term_get(advertiser_id, term_type, access_token, lang=lang) pprint(api_response) except ApiException as e: print("Exception when calling AccountManagementApi->term_get: %s\n" % e) ``` -------------------------------- ### Python SDK Example Usage Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/README.md Illustrative Python code demonstrating how to interact with the TikTok Business API SDK. This example shows basic API call structure, though specific SDK methods are not detailed here. ```Python # Example of how to initialize and use the TikTok Business API SDK # Note: This is a conceptual example. Actual SDK usage may vary. # from tiktok_business_sdk import TikTokBusinessAPI # # Initialize the API client with your access token and advertiser ID # api = TikTokBusinessAPI(access_token='YOUR_ACCESS_TOKEN', advertiser_id='YOUR_ADVERTISER_ID') # # Example: Get a list of portfolios # try: # portfolios = api.creative_management.creative_portfolio_list() # print("Successfully retrieved portfolios:", portfolios) # except Exception as e: # print(f"An error occurred: {e}") # # Example: Upload a video # try: # with open('path/to/your/video.mp4', 'rb') as video_file: # upload_response = api.file.ad_video_upload(file=video_file) # print("Video upload response:", upload_response) # except FileNotFoundError: # print("Video file not found.") # except Exception as e: # print(f"An error occurred during video upload: {e}") ``` -------------------------------- ### Get BC Assets using Python SDK Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/BCApi.md Provides an example of retrieving assets associated with a Business Center as administrators using the TikTok Business API Python SDK. It covers parameter usage for filtering and pagination. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.BCApi() bc_id = 'bc_id_example' # str | asset_type = 'asset_type_example' # str | access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). child_bc_id = 'child_bc_id_example' # str | (optional) filtering = business_api_client.FilteringBcAssetAdminGet() # FilteringBcAssetAdminGet | (optional) page = 1 # int | (optional) (default to 1) page_size = 10 # int | (optional) (default to 10) try: # Get assets of a Business Center as admins. [BC Asset Admin Get](https://business-api.tiktok.com/portal/docs?id=1739433007779841) api_response = api_instance.bc_asset_admin_get(bc_id, asset_type, access_token, child_bc_id=child_bc_id, filtering=filtering, page=page, page_size=page_size) pprint(api_response) except ApiException as e: print("Exception when calling BCApi->bc_asset_admin_get: %s\n" % e) ``` -------------------------------- ### Python SDK Example: Run Synchronous Report Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/ReportingApi.md Example demonstrating how to use the Python SDK to call the `report_integrated_get` method for running a synchronous report. It shows how to instantiate the client and handle potential API exceptions. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.ReportingApi() report_type = 'report_type_example' # str | access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). page = 1 # int | (optional) (default to 1) page_size = 10 # int | (optional) (default to 10) enable_total_metrics = False # bool | (optional) (default to false) multi_adv_report_in_utc_time = False # bool | (optional) (default to false) query_mode = 'query_mode_example' # str | (optional) advertiser_id = 'advertiser_id_example' # str | (optional) advertiser_ids = ['advertiser_ids_example'] # list[str] | (optional) bc_id = 'bc_id_example' # str | (optional) service_type = 'service_type_example' # str | (optional) data_level = 'data_level_example' # str | (optional) dimensions = ['dimensions_example'] # list[str] | (optional) metrics = ['metrics_example'] # list[str] | (optional) start_date = 'start_date_example' # str | (optional) end_date = 'end_date_example' # str | (optional) query_lifetime = True # bool | (optional) order_field = 'order_field_example' # str | (optional) order_type = 'order_type_example' # str | (optional) filtering = None # list[object] | (optional) try: # Run a synchronous report. [Report Integrated Get](https://business-api.tiktok.com/portal/docs?id=1740302848100353) api_response = api_instance.report_integrated_get(report_type, access_token, page=page, page_size=page_size, enable_total_metrics=enable_total_metrics, multi_adv_report_in_utc_time=multi_adv_report_in_utc_time, query_mode=query_mode, advertiser_id=advertiser_id, advertiser_ids=advertiser_ids, bc_id=bc_id, service_type=service_type, data_level=data_level, dimensions=dimensions, metrics=metrics, start_date=start_date, end_date=end_date, query_lifetime=query_lifetime, order_field=order_field, order_type=order_type, filtering=filtering) pprint(api_response) except ApiException as e: print("Exception when calling ReportingApi->report_integrated_get: %s\n" % e) ``` -------------------------------- ### Create TikTok Campaign Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/CampaignCreationApi.md Example of how to create a new advertising campaign using the TikTok Business API SDK. This involves setting campaign objectives and budget. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.CampaignCreationApi() access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). body = business_api_client.CampaignCreateBody() # CampaignCreateBody | Campaign create body parameters (optional) try: # To create a campaign. To advertise on TikTok Ads, you need to create a campaign and set the Advertising objectives and budget. A regular campaign can contain one or more ad groups. [Campaign Create](https://ads.tiktok.com/marketing_api/docs?id=1739318962329602) api_response = api_instance.campaign_create(access_token, body=body) pprint(api_response) except ApiException as e: print("Exception when calling CampaignCreationApi->campaign_create: %s\n" % e) ``` -------------------------------- ### Get App Conversion Events using TikTok Business API SDK (Python) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/README.md Demonstrates how to retrieve app conversion events for optimization purposes. This example requires an `app_id`, `advertiser_id`, `optimization_goal`, and `access_token`, with several optional parameters available for filtering and configuration. It includes error handling for potential `ApiException`. ```python # create an instance of the API class api_instance = business_api_client.APPManagementApi(business_api_client.ApiClient(configuration)) app_id = 'app_id_example' # str | Your App ID, obtained after successfully creating your app. advertiser_id = 'advertiser_id_example' # str | Advertiser ID optimization_goal = 'optimization_goal_example' # str | Optimization goal. For enum values, see Enumeration-Optimization Goal for more access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). placement = ['placement_example'] # list[str] | The apps where you want to deliver your ads. Required when placement_type is PLACEMENT_TYPE_NORMAL, and ignored when placement_type is PLACEMENT_TYPE_AUTOMATIC. Note: Currently, we support PLACEMENT_TIKTOK, PLACEMENT_PANGLE and PLACEMENT_GLOBAL_APP_BUNDLE. Please don't select PLACEMENT_TOPBUZZ or PLACEMENT_HELO as your placements since they've been deprecated. For a full list of enum values, see Enumeration - Placement. For Product Sales campaigns (objective_type = PRODUCT_SALES), only TikTok placement (PLACEMENT_TIKTOK) is supported. (optional) placement_type = 'placement_type_example' # str | 版位类型。 枚举值:PLACEMENT_TYPE_AUTOMATIC(自动版位),PLACEMENT_TYPE_NORMAL (编辑版位)。 默认值: PLACEMENT_TYPE_NORMAL。 (optional) objective = 'objective_example' # str | Advertising Objective. For enum values, see Enumeration-Advertising Objective (optional) available_only = true # bool | Whether to return only available conversion events. The default value: True (only return available conversion events) (optional) is_skan = true # bool | Whether the app is using Skan features. (optional) app_promotion_type = 'app_promotion_type_example' # str | App promotion type. Required when objective_type is APP_PROMOTION. Enum values: APP_INSTALL, APP_RETARGETING. Note: APP_INSTALL can be used in an iOS14 Dedicated Campaign, while APP_RETARGETING cannot be used. (optional) try: # Get App Conversion Events. [App Optimization Event](https://business-api.tiktok.com/portal/docs?id=1740859338750977) api_response = api_instance.app_optimization_event(app_id, advertiser_id, optimization_goal, access_token, placement=placement, placement_type=placement_type, objective=objective, available_only=available_only, is_skan=is_skan, app_promotion_type=app_promotion_type) pprint(api_response) except ApiException as e: print("Exception when calling APPManagementApi->app_optimization_event: %s\n" % e) ``` -------------------------------- ### Update Automated Rule Example Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/AutomatedRulesApi.md Python example demonstrating how to use the TikTok Business API SDK to update an automated rule. It shows how to instantiate the client, call the optimizer_rule_update method, and handle potential API exceptions. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.AutomatedRulesApi() access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). body = business_api_client.OptimizerRuleUpdateBody() # OptimizerRuleUpdateBody | (optional) try: # Update an automated rule. [Optimizer Rule Update](https://business-api.tiktok.com/portal/docs?id=1738769123170306) api_response = api_instance.optimizer_rule_update(access_token, body=body) pprint(api_response) except ApiException as e: print("Exception when calling AutomatedRulesApi->optimizer_rule_update: %s\n" % e) ``` -------------------------------- ### Upload TikTok Products via File URL Example Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/CatalogApi.md Python example for uploading products to a TikTok catalog using a file URL. This snippet shows the usage of the catalog_product_file method, requiring an access token and an optional body for file details. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.CatalogApi() access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). body = business_api_client.ProductUploadBody() # ProductUploadBody | (optional) try: # Upload products via file URL. [Catalog Product File](https://business-api.tiktok.com/portal/docs?id=1740496787164161) api_response = api_instance.catalog_product_file(access_token, body=body) pprint(api_response) except ApiException as e: print("Exception when calling CatalogApi->catalog_product_file: %s\n" % e) ``` -------------------------------- ### Get Contextual Tags (Python) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/ToolApi.md Example of how to instantiate the TikTok Business API client and call the `tool_contextual_tag_get` method to retrieve contextual tags. It includes setting up parameters like advertiser ID, objective type, and access token, and demonstrates error handling for API exceptions. ```python # create an instance of the API class api_instance = business_api_client.ToolApi() advertiser_id = 'advertiser_id_example' # str | Advertiser ID. objective_type = 'objective_type_example' # str | Advertising objective. Only supports REACH, VIDEO_VIEWS, RF_REACH. access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). region_codes = ['region_codes_example'] # list[str] | Country or region codes. (optional) brand_safety_type = 'brand_safety_type_example' # str | Brand safety type. Default value: STANDARD_INVENTORY. Enum values: EXPANDED_INVENTORY: Use TikTok's brand safety solution. Expanded inventory means that your ads will appear next to content where most inappropriate content has been removed, and may contain some mature themes. In the next API version, EXPANDED_INVENTORY will replace NO_BRAND_SAFETY and will be the default brand safety option. STANDARD_INVENTORY: Use TikTok's brand safety solution. Standard inventory means that ads will appear next to content that is appropriate for most brands. LIMITED_INVENTORY: Use TikTok's brand safety solution. Limited inventory means that your ads will not appear next to content that contains mature themes. Note: Pre-bid first-party Brand Safety solutions for APP_PROMOTION, WEB_CONVERSIONS, TRAFFIC, LEAD_GENERATION objectives in Auction ads, and pre-bid third-party brand safety solutions are currently allowlist-only features. If you would like to access them, please contact your TikTok representative. See Brand safety to learn about the supported advertising objectives for pre-bid Brand Safety filtering. (optional) rf_campaign_type = 'rf_campaign_type_example' # str | Note: When objective_type is specified as RF_REACH, use this field to set the campaign as a TikTok Pulse campaign, then you can get available premium contextual tags. Do not pass in this field when objective_type is not specified as RF_REACH. Enum values: STANDARD (Reach & Frequency campaign), PULSE(TikTok Pulse campaign) (optional) try: # Get available contextual tags [Tool Contextual_tag Get](https://ads.tiktok.com/marketing_api/docs?id=1747747118654465) api_response = api_instance.tool_contextual_tag_get(advertiser_id, objective_type, access_token, region_codes=region_codes, brand_safety_type=brand_safety_type, rf_campaign_type=rf_campaign_type) pprint(api_response) except ApiException as e: print("Exception when calling ToolApi->tool_contextual_tag_get: %s\n" % e) ``` -------------------------------- ### Python SDK Example: Creative Asset Delete Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/CreativeManagementApi.md Example of how to use the Python SDK to delete creative assets. This snippet demonstrates initializing the API client and calling the delete method. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # Configure API key authorization: # api_key = 'YOUR_API_KEY' # create an instance of the API class api_client = business_api_client.ApiClient() api = business_api_client.CreativeManagementApi(api_client) # Example: Delete creative assets access_token = 'YOUR_ACCESS_TOKEN' asset_ids = ['asset_id_1', 'asset_id_2'] # Replace with actual asset IDs try: # Assuming the body parameter is a list of asset IDs or a dictionary containing them # The exact structure depends on the SDK's generated model for the request body # For demonstration, let's assume a simple list is passed or a dict like {'asset_ids': asset_ids} # Consult the SDK documentation for the precise 'body' structure. # Example placeholder for body: body_payload = {'asset_ids': asset_ids} api_response = api.creative_asset_delete(access_token=access_token, body=body_payload) pprint(api_response) except ApiException as e: print("Exception when calling CreativeManagementApi->creative_asset_delete: %s\n" % e) ``` -------------------------------- ### TikTok Business API: Ad Account Creation Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/README.md Create a new ad account within a Business Center. This endpoint facilitates the setup of new advertising entities. ```APIDOC bc_advertiser_create POST /bc/advertiser/create/ Create an ad account [BC advertiser create]. Parameters: - (Required) business_center_id: The ID of the Business Center to create the ad account in. - (Required) name: The name for the new ad account. - (Optional) currency_code: The currency for the ad account (e.g., USD, EUR). - (Optional) timezone: The timezone for the ad account. Returns: - Details of the newly created ad account, including its ID. ``` -------------------------------- ### Search Targeting Hashtags (Python) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/ToolApi.md Shows how to search for targeting hashtags by providing keywords and an optional operator (AND/OR). Includes setup, API call, and exception handling. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.ToolApi() advertiser_id = 'advertiser_id_example' # str | Advertiser ID. keywords = ['keywords_example'] # list[str] | Keywords that you want to get recommended hashtags for. If you specify multiple unrelated keywords and set operator to AND, it is possible that no recommended hashtags are returned. Max size: 10. access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). operator = 'AND' # str | The operator to be used between the keywords. Enum values: AND: Recommended hashtags will be generated based on all the keywords specified in keywords. OR: Recommended hashtags will be generated separately for each individual keyword in keywords. Default value: AND. (optional) (default to AND) try: # Search for targeting hashtags [Tool Hashtag Recommend](https://ads.tiktok.com/marketing_api/docs?id=1736271339521025) api_response = api_instance.tool_hashtag_recommend(advertiser_id, keywords, access_token, operator=operator) pprint(api_response) except ApiException as e: print("Exception when calling ToolApi->tool_hashtag_recommend: %s\n" % e) ``` -------------------------------- ### TikTok API: Get Available Locations (Tool Region) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/ToolApi.md API documentation for the `tool_region` endpoint of the TikTok Business API SDK. This method retrieves available locations based on specified criteria such as advertiser ID, placements, objective type, and operating system. It details parameters, return types, and provides an example setup. ```APIDOC tool_region(advertiser_id, placements, objective_type, access_token, promotion_target_type=promotion_target_type, operating_system=operating_system, brand_safety_type=brand_safety_type, brand_safety_partner=brand_safety_partner, level_range=level_range, rf_campaign_type=rf_campaign_type) Get available locations [Tool Region](https://ads.tiktok.com/marketing_api/docs?id=1737189539571713) Parameters: advertiser_id (str): Advertiser ID. placements (list[str]): Placements for the campaign. objective_type (str): Objective type for the campaign. access_token (str): Authorized access token. promotion_target_type (str, optional): Promotion target type. Defaults to None. operating_system (str, optional): Operating system. Defaults to None. brand_safety_type (str, optional): Brand safety type. Defaults to None. brand_safety_partner (str, optional): Brand safety partner. Defaults to None. level_range (str, optional): Level range. Defaults to None. rf_campaign_type (str, optional): RF campaign type. Defaults to None. Return type: InlineResponse200 Example: from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.ToolApi() advertiser_id = 'advertiser_id_example' # str | Advertiser ID. placements = ['PLACEMENT_1', 'PLACEMENT_2'] # list[str] | Placements for the campaign. objective_type = 'OBJECTIVE_TYPE_1' # str | Objective type for the campaign. access_token = 'access_token_example' # str | Authorized access token. try: # Get available locations [Tool Region](https://ads.tiktok.com/marketing_api/docs?id=1737189539571713) api_response = api_instance.tool_region(advertiser_id, placements, objective_type, access_token) pprint(api_response) except ApiException as e: print("Exception when calling ToolApi->tool_region: %s\n" % e) ``` -------------------------------- ### Python SDK Initialization and Campaign Setup Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/ToolApi.md Demonstrates how to initialize the TikTok Business API client and set up parameters for a campaign. This snippet shows the typical structure for preparing API calls. ```python # create an instance of the API class api_instance = business_api_client.ToolApi() advertiser_id = 'advertiser_id_example' # str | Advertiser ID. objective_type = 'objective_type_example' # str | Advertising objective. Set this field to APP_PROMOTION, WEB_CONVERSIONS, or PRODUCT_SALES. When you set this field to any other objective, vo_status will be NOT_SUPPORT because these objectives are not supported for VBO. For enum values and descriptions, see Objectives. Note: When objective_type is set to PRODUCT_SALES and promotion_type is set to LIVE_SHOPPING or VIDEO_SHOPPING, do not pass in pixel_id or app_id. Otherwise, pass in either pixel_id or app_id. promotion_type = 'promotion_type_example' # str | Promotion type and you can decide where you'd like to promote your products using this field. For enum values, see Enumeration - Promotion Type. Note: When objective_type is set to PRODUCT_SALES and promotion_type is set to LIVE_SHOPPING or VIDEO_SHOPPING, do not pass in pixel_id or app_id. Otherwise, pass in either pixel_id or app_id. placements = ['placements_example'] # list[str] | The apps where you want to deliver your ads. Note: Currently, we support PLACEMENT_TIKTOK, PLACEMENT_PANGLE and PLACEMENT_GLOBAL_APP_BUNDLE. For Product Sales campaigns (objective_type = PRODUCT_SALES), only TikTok placement (PLACEMENT_TIKTOK) is supported. access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). pixel_id = 'pixel_id_example' # str | Not supported when objective_type is set to PRODUCT_SALES and promotion_type is set to LIVE_SHOPPING or VIDEO_SHOPPING. Otherwise, pass in either pixel_id or app_id. Pixel ID. When you pass in this field, you need to specify optimization_event at the same time. To get Pixel IDs, use the /pixel/list/ endpoint. (optional) app_id = 'app_id_example' # str | Not supported when objective_type is set to PRODUCT_SALES and promotion_type is set to LIVE_SHOPPING or VIDEO_SHOPPING. Otherwise, pass in either pixel_id or app_id. The Application ID of the promoted app. To get App IDs, use the /app/list/ endpoint. (optional) optimization_event = 'optimization_event_example' # str | Required when pixel_id is passed. Ignored when app_id is passed. Conversion event for the ad group. See Conversion events for more. (optional) ios14_quota_type = 'ios14_quota_type_example' # str | Do not pass campaign_type and ios14_quota_type at the same time. If both fields are passed, ios14_quota_type will be ignored. We recommend using campaign_type alone when you specify an iOS 14 Dedicated Campaign. campaign_type as REGULAR_CAMPAIGN or ios14_quota_type as UNOCCUPIED both indicate a non-iOS 14 Dedicated Campaign. campaign_type as IOS14_CAMPAIGN or ios14_quota_type as OCCUPIED both indicate an iOS 14 Dedicated Campaign. Whether the campaign will be counted towards the iOS 14 Dedicated Campaign quota. Enum values: OCCUPIED: The campaign is an iOS 14 Dedicated Campaign. UNOCCUPIED: The campaign is not an iOS 14 Dedicated Campaign. (optional) app_promotion_type = 'app_promotion_type_example' # str | Required when objective_type is APP_PROMOTION. App promotion type. Enum values: APP_INSTALL: Get new users to install your app. APP_RETARGETING: Re-engage existing users to take action in your app. Note: Only the enum value APP_INSTALL can be used in an iOS14 Dedicated Campaign. (optional) store_id = 'store_id_example' # str | Valid only when objective_type is PRODUCT_SALES. ID of the TikTok Shop. Note: To get the TikTok Shop ID, you can use /bc/asset/get/: When in the response asset_type is TIKTOK_SHOP, the returned asset_id is the TikTok Shop ID. (optional) campaign_app_profile_page_state = 'campaign_app_profile_page_state_example' # str | Whether to use App Profile Page at the campaign level to optimize delivery. Enum values: ON, OFF. You can use the field only when objective_type is APP_PROMOTION and your campaign is an iOS14 Dedicated Campaign (ios14_quota_type =OCCUPIED). Otherwise, an error will occur. (optional) is_smart_performance_campaign = true # bool | Whether the campaign is a Smart+ Campaign or not. Enum values: true, false. (optional) budget_optimize_on = false # bool | Whether to enable Campaign Budget Optimization (CBO). Enum values: true, false. For details about CBO, see Campaign Budget Optimization. (optional) (default to false) campaign_type = 'campaign_type_example' # str | Do not pass campaign_type and ios14_quota_type at the same time. If both fields are passed, ios14_quota_type will be ignored. Campaign type. Enums values: REGULAR_CAMPAIGN: non-iOS 14 Dedicated Campaign. IOS14_CAMPAIGN: iOS 14 Dedicated Campaign. The value IOS14_CAMPAIGN can only be used when: objective_type is PRODUCT_SALES. objective_type is APP_PROMOTION and app_promotion_type is APP_INSTALL. (optional) try: # Example of how these parameters might be used in an API call # response = api_instance.create_campaign( # advertiser_id=advertiser_id, # objective_type=objective_type, # promotion_type=promotion_type, # placements=placements, # access_token=access_token, # pixel_id=pixel_id, # app_id=app_id, # optimization_event=optimization_event, # ios14_quota_type=ios14_quota_type, # app_promotion_type=app_promotion_type, # store_id=store_id, # campaign_app_profile_page_state=campaign_app_profile_page_state, # is_smart_performance_campaign=is_smart_performance_campaign, # budget_optimize_on=budget_optimize_on, # campaign_type=campaign_type # ) pass # Placeholder for actual API call except Exception as e: print(f"An error occurred: {e}") ``` -------------------------------- ### Fetch Tool Language (Python SDK) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/README.md Demonstrates how to use the TikTok Business API SDK to fetch supported tool languages for an advertiser. It includes API client instantiation and error handling. ```python from __future__ import print_function import business_api_client from business_api_client.rest import ApiException from pprint import pprint # Placeholder for actual values 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) test_tool_language() ``` -------------------------------- ### TikTok Business API tool_action_category Method Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/ToolApi.md API method to get action categories, optionally filtered by special industries. Includes parameter details, return types, and a Python usage example. ```APIDOC tool_action_category(advertiser_id, access_token, special_industries=special_industries) Get action categories [Tool action](https://ads.tiktok.com/marketing_api/docs?id=1737166752522241) Parameters: advertiser_id (str): Advertiser ID. [required] access_token (str): Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). [required] special_industries (list[str]): Ad categories. Enum values: `HOUSING`: Ads for real estate listings, homeowners insurance, mortgage loans or other related opportunities. `EMPLOYMENT`: Ads for job offers, internship, professional certification programs or other related opportunities. `CREDIT`: Ads for credit card offers, auto loans, long-term financing or other related opportunities. Note: This field is only supported for advertisers who are registered in America or Canada. [optional] Return type: [InlineResponse200](InlineResponse200.md) HTTP request headers: - Content-Type: Not defined - Accept: application/json ``` -------------------------------- ### Get Related Comments (Python) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/CommentsApi.md Example of how to retrieve related comments using the TikTok Business API SDK. It demonstrates setting up the API client and calling the comment_reference method with various parameters. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.CommentsApi() advertiser_id = 'advertiser_id_example' # str | comment_id = 'comment_id_example' # str | comment_type = 'comment_type_example' # str | access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). original_comment_id = '0' # str | (optional) (default to 0) app = 'TIKTOK' # str | (optional) (default to TIKTOK) page = 1 # int | (optional) (default to 1) page_size = 10 # int | (optional) (default to 10) try: # Get related comments. [Comment Reference](https://business-api.tiktok.com/portal/docs?id=1738086824859650) api_response = api_instance.comment_reference(advertiser_id, comment_id, comment_type, access_token, original_comment_id=original_comment_id, app=app, page=page, page_size=page_size) pprint(api_response) except ApiException as e: print("Exception when calling CommentsApi->comment_reference: %s\n" % e) ``` -------------------------------- ### Python SDK: Update Campaign Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/CampaignCreationApi.md Example demonstrating how to update a TikTok campaign using the Python SDK. It covers setting up the API client, making the update call, and handling potential exceptions. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.CampaignCreationApi() access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). body = business_api_client.CampaignUpdateBody() # CampaignUpdateBody | Campaign update body parameters (optional) try: # To modify a campaign after it has been created. Information like campaign name, budget, and budget type can be updated. [Campaign Update](https://ads.tiktok.com/marketing_api/docs?id=1739320422086657) api_response = api_instance.campaign_update(access_token, body=body) pprint(api_response) except ApiException as e: print("Exception when calling CampaignCreationApi->campaign_update: %s\n" % e) ``` -------------------------------- ### Get Recommended Targeting Categories (Python) Source: https://github.com/rithvikgabri/tiktok-business-api-sdk-python/blob/main/python_sdk/docs/RecommendToolApi.md Example demonstrating how to use the RecommendToolApi to fetch recommended interest and action categories. It requires an authorized access token and optionally accepts a body object for specific parameters. ```python from __future__ import print_function import time import business_api_client from business_api_client.rest import ApiException from pprint import pprint # create an instance of the API class api_instance = business_api_client.RecommendToolApi() access_token = 'access_token_example' # str | Authorized access token. For details, see [Authentication](https://ads.tiktok.com/marketing_api/docs?id=1738373164380162). body = business_api_client.TargetingCategoryRecommendBody() # TargetingCategoryRecommendBody | Tool recommend body parameters (optional) try: # Get recommended interest and action categories [Tool targeting category](https://ads.tiktok.com/marketing_api/docs?id=1736275204260866) api_response = api_instance.tool_targeting_category_recommend(access_token, body=body) pprint(api_response) except ApiException as e: print("Exception when calling RecommendToolApi->tool_targeting_category_recommend: %s\n" % e) ```