快速入门
本指南介绍如何使用商业内容 API。通过以下示例,了解如何使用商业内容 API 查询广告数据和获取公开的广告主数据。
查看你的客户端注册信息
你的申请通过审核后,系统将为你的项目生成一个研究客户端。你可点击此处查看已通过审核的研究项目。从列表中选择一个项目,查看对应的研究客户端的详细信息。
连接商业内容 API 端点时,需要使用 TikTok 提供的 Client Key 和 Client Secret。Client Key 和 Client Secret 默认隐藏,可点击【显示】按钮(眼睛图标)查看。
注意:Client Secret 是连接 TikTok API 时的身份验证凭证。请勿向任何人透露。
获取客户端访问令牌
获取到项目的 Client Key 和 Client Secret 后,即可生成客户端访问令牌。将生成的访问令牌添加到 HTTP 请求的授权标头 (Authorization) 中,以连接商业内容 API 端点。
查询 TikTok 公开内容数据
以下 cURL 命令示例展示如何使用关键词“coffee”查询 2021 年 1 月 2 日至 2021 年 1 月 9 日期间创建地为意大利的 TikTok 广告。
curl -X POST 'https://open.tiktokapis.com/v2/research/adlib/ad/query/?fields=ad.id' \ -H 'authorization: bearer clt.example12345Example12345Example' \ -d '{ "filters": { "ad_published_date_range": { "min": "20221001", "max": "20230510" }, "country_code": "IT" }, "search_term": "coffee", "max_count": 10 }'分页
如果符合查询条件的广告总数大于单次请求可返回的最大广告数量,可以通过多次请求获取全部返回结果。
字段 | 类型 | 描述 | 示例 | 是否必填 |
max_count | 数值 (Number) | 响应中可返回的 TikTok 视频最大数量。默认值为 10。 | 10 | 否 |
search_id | 字符串 (String) | 上次查询的 search_id。分页查询时,按顺序继续获取上次查询的结果。 | "eyJsYXN0X3NvcnQiOls3NDA3OCwiMzUwNDIwOTgzOD" | 否 |
查询首页结果
发送首次查询请求时,无需在请求体中设置 search_id。HTTP 响应中会返回 has_more 和 search_id,用于后续请求。
请求示例:curl -X POST 'https://open.tiktokapis.com/v2/research/adlib/ad/query/?fields=ad.id' \ -H 'authorization: bearer clt.example12345Example12345Example' \ -d '{ "filters": { "ad_published_date_range": { "min": "20221001", "max": "20230510" }, "country_code": "IT" }, "search_term": "coffee", "max_count": 10 }'返回数据示例:
{ "data": { "has_more": true, "search_id": "eyJsYXN0X3NvcnQiOls3NDA3OCwiMzUwNDIwOTgzOD", "ads": [ ... ] }, "error": { ... } }获取下一页结果
你可以使用以下 cURL 命令获取下一页的查询结果。
curl -X POST 'https://open.tiktokapis.com/v2/research/adlib/ad/query/?fields=ad.id' \ -H 'authorization: bearer clt.example12345Example12345Example' \ -d '{ "filters": { "ad_published_date_range": { "min": "20221001", "max": "20230510" }, "country_code": "IT" }, "search_term": "coffee", "max_count": 10, "search_id": "eyJsYXN0X3NvcnQiOls3NDA3OCwiMzUwNDIwOTgzOD" }'返回数据示例:
{ "data": { "has_more": true, "search_id": "eyJsYXN0X3NvcnQiOlsyNTQxMTkwLCIzNDk1NzA4NjI", "ads": [ ... ] }, "error": { ... } }