← 返回目录
📁 Organic API › Accounts API › Guides › Get started

获取访问令牌

TikTok 账号用户授权后,您会收到的授权码,您可向以下接口发送请求,获取后续申请访问接口所需的 TikTok 账号访问令牌以及用于刷新访问令牌的 TikTok 账号刷新令牌。

欲获取 TikTok 账号用户授予的 TikTok 账号权限范围信息,可将生成的访问令牌传入/tt_user/token_info/get/接口进行查询。

访问令牌到期

TikTok 账号访问令牌的有效期为 1 天。TikTok 账号访问令牌到期后,您需要向此接口发送请求,以刷新访问令牌。发送令牌刷新请求时,请传入刷新令牌(refresh_token)。

刷新令牌到期

TikTok 账号刷新令牌的有效期为 1 年。如果刷新令牌到期,开发者需要向用户发送请求,通过用户授权流程对应用重新授权。

获取、刷新或撤销 TikTok 账号访问令牌

获取 TikTok 账号访问令牌

您可以使用本接口获取 TikTok 账号访问令牌。

请求

地址 https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/token/

方法 POST

Header

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|Content-Type {必填}|string|请求消息类型。<br>允许格式:`application/json`。 |

参数

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|client_id {必填}|string|开发者应用 ID。<br><br>若想获取<strong>应用 ID</strong>,可以导航至<strong>[应用管理](https://ads.tiktok.com/marketing_api/apps/)</strong> > <strong>App Detail</strong> > <strong>基本信息</strong>。 |
|client_secret {必填}|string| 开发者应用密钥。<br><br>若想获取<strong>密钥</strong>,可以导航至<strong>[应用管理](https://ads.tiktok.com/marketing_api/apps/)</strong> > <strong>App Detail</strong> > <strong>基本信息</strong>。|
|grant_type {必填}|string|生成访问令牌的方式。<br><br>允许的枚举值:<ul><li>`authorization_code`:通过授权码生成访问令牌。</li></ul>|
|auth_code {必填}|string| 您的 <strong>TikTok 账户授权 URL </strong>生成的授权码(`auth_code`)。<br><br>授权码有效期为 10 分钟且只能使用一次。<br><br>若想了解您使用的 API 类别对应的授权码获取方式,可查看[不同 API 的授权流程对比](https://business-api.tiktok.com/portal/docs?id=1781891256601602#item-link-%E4%B8%8D%E5%90%8C%20API%20%E7%9A%84%E6%8E%88%E6%9D%83%E6%B5%81%E7%A8%8B%E5%AF%B9%E6%AF%94)中的"<strong>OAuth 授权 URL</strong>"行。  |
|redirect_uri {必填}|string| 客户将跳转的重定向 URL。<br><br>传入的值必须和开发者应用中的 <b>TikTok 账户持有人重定向 URL </b>保持一致。|
示例
(code curl http)
curl --location --request POST 'https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/token/' \
--header 'Content-Type: application/json' \
--data '{
    "client_id":"{{client_id}}",
    "client_secret":"{{client_secret}}",
    "grant_type":"authorization_code",
    "auth_code":"{{auth_code}}",
    "redirect_uri":"{{redirect_uri}}"
}'
(/code)

返回

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|code |number|返回码。完整返回码列表及描述,可查看[附录 - 返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|message |string|返回信息。更多信息可查看[附录 - 返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|request_id|string|请求的日志 ID,唯一标识一个请求。|
|data|object|返回数据。|
#|access_token|string|用于权限验证的短期访问令牌。该令牌有效期为 1 天。|
#|token_type|string|令牌类型。<br><br>枚举值:<ul><li>`Bearer`:不记名令牌,拥有该令牌后任何人均可访问相关资源。</li></ul>|
#|scope|string|该访问令牌所拥有的权限。|
#|expires_in|number|访问令牌的剩余有效时长,以秒为单位。|
#|refresh_token|string|用于刷新访问令牌的刷新令牌。刷新令牌有效期为 1 年。<br><br><p><span style="color:darkred"><b>注意</b></span>:请保留此字段,用于刷新`access_token`。|
#|refresh_token_expires_in|number|刷新令牌的剩余有效时长,以秒为单位。|
#|open_id|string|TikTok 账户的应用唯一识别 ID。|
示例
(code Success-Response http)
HTTPS/1.1 200 OK
{
    "code": 0,
    "message": "OK",
    "request_id": "{{request_id}}",
    "data": {
        "access_token": "{{access_token}}",
        "expires_in": 86400,
        "open_id": "{{open_id}}",
        "refresh_token": "{{refresh_token}}",
        "refresh_token_expires_in": 31536000,
        "scope": "message.list.manage,video.list,video.insights,user.insights,user.info.basic,comment.list,biz.brand.insights,biz.spark.auth,tcm.order.update,comment.list.manage,video.upload,video.publish,biz.ads.recommend,user.account.type,biz.creator.info,user.info.username,message.list.send,user.info.profile,user.info.stats,message.list.read,biz.creator.insights",
        "token_type": "Bearer"
    }
}

(/code)

刷新 TikTok 账号访问令牌

您可以通过本接口使用 TikTok 账号刷新令牌刷新访问令牌。

请求

地址 https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/refresh_token/

方法 POST

Header

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|Content-Type {必填}|string|请求消息类型。<br>允许格式:`application/json`。 |

参数

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|client_id {必填}|string|开发者应用 ID。<br><br>若想获取<strong>应用 ID</strong>,可以导航至<strong>[应用管理](https://ads.tiktok.com/marketing_api/apps/)</strong> > <strong>App Detail</strong> > <strong>基本信息</strong>。 |
|client_secret {必填}|string| 开发者应用密钥。<br><br>若想获取<strong>密钥</strong>,可以导航至<strong>[应用管理](https://ads.tiktok.com/marketing_api/apps/)</strong> > <strong>App Detail</strong> > <strong>基本信息</strong>。|
|grant_type {必填}|string|生成访问令牌的方式。<br><br>允许的枚举值:<ul><li>`refresh_token`:通过刷新令牌生成访问令牌。</li></ul>|
|refresh_token {必填}|string| 刷新令牌,用于刷新现有的访问令牌。<br><br>您可在使用<a href="#item-link-获取 TikTok 账号访问令牌">/tt_user/oauth2/token/</a>生成访问令牌时的返回中获取刷新令牌。|
示例
(code curl http)
curl --location --request POST 'https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/refresh_token/' \
--header 'Content-Type: application/json' \
--data '{
    "client_id":"{{client_id}}",
    "client_secret":"{{client_secret}}",
    "grant_type":"refresh_token",
    "refresh_token":"{{refresh_token}}"
}'
(/code)

返回

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|code |number|返回码。完整返回码列表及描述,可查看[附录 - 返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|message |string|返回信息。更多信息可查看[附录 - 返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|request_id|string|请求的日志 ID,唯一标识一个请求。|
|data|object|返回数据。|
#|access_token|string|用于权限验证的短期访问令牌。该令牌有效期为 1 天。|
#|token_type|string|令牌类型。<br><br>枚举值:<ul><li>`Bearer`:不记名令牌,拥有该令牌后任何人均可访问相关资源。</li></ul>|
#|scope|string|该访问令牌所拥有的权限。|
#|expires_in|number|访问令牌的剩余有效时长,以秒为单位。|
#|refresh_token|string|用于刷新访问令牌的刷新令牌。刷新令牌有效期为 1 年。<br><br><p><span style="color:darkred"><b>注意</b></span>:请保留此字段,用于刷新`access_token`。|
#|refresh_token_expires_in|number|刷新令牌的剩余有效时长,以秒为单位。|
#|open_id|string|TikTok 账户的应用唯一识别 ID。|
示例
(code Success-Response http)
HTTPS/1.1 200 OK
{
    "code": 0,
    "message": "OK",
    "request_id": "{{request_id}}",
    "data": {
        "access_token": "{{access_token}}",
        "expires_in": 86400,
        "open_id": "{{open_id}}",
        "refresh_token": "{{refresh_token}}",
        "refresh_token_expires_in": 28484364,
        "scope": "message.list.manage,video.list,video.insights,user.insights,user.info.basic,comment.list,biz.brand.insights,biz.spark.auth,tcm.order.update,comment.list.manage,video.upload,video.publish,biz.ads.recommend,user.account.type,biz.creator.info,user.info.username,message.list.send,user.info.profile,user.info.stats,message.list.read,biz.creator.insights",
        "token_type": "Bearer"
    }
}
(/code)

撤销 TikTok 账号访问令牌

您可以使用本接口撤销 TikTok 账号访问令牌。

请求

地址 https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/revoke/

方法 POST

Header

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|Content-Type {必填}|string|请求信息类型。<br>允许格式:`application/json`。|

参数

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
| client_id {必填} | string |开发者应用ID。<br><br>若想获取<strong>应用ID</strong>,您可以导航至<strong>[应用管理](https://ads.tiktok.com/marketing_api/apps/)</strong> > <strong>App Detail</strong> > <strong>基本信息</strong>。|
| client_secret {必填} | string | 开发者应用密钥。<br><br>若想获取<strong>密钥</strong>,您可以导航至<strong>[应用管理](https://ads.tiktok.com/marketing_api/apps/)</strong> > <strong>App Detail</strong> > <strong>基本信息</strong>。|
| access_token{必填} | string | 您想要撤销的 TikTok 账号访问令牌。<br><br>您可使用<a href="#item-link-获取 TikTok 账号访问令牌">/tt_user/oauth2/token/</a>创建新的访问令牌,或使用<a href="#item-link-刷新 TikTok 账号访问令牌">/tt_user/oauth2/refresh_token/</a>获取刷新后的访问令牌。|
示例
(code curl http)
curl --location --request POST 'https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/revoke/' \
--header 'Content-Type: application/json' \
--data '{
    "client_id":"{{client_id}}",
    "client_secret":"{{client_secret}}",
    "access_token":"{{access_token}}"
}'
(/code)

返回

|字段{30%}|类型{15%}|描述{55%}|
|---|---|---|
|code |number| 返回码。完整返回码列表及描述,参见 [附录 - 返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。|
|message |string| 返回信息。更多信息参见 [附录 - 返回码](https://ads.tiktok.com/marketing_api/docs?id=1737172488964097)。 |
|request_id |string| 请求的日志 ID,唯一标识一个请求。 |
|data |object| 返回数据。 |
示例
(code Success-Response http)
HTTPS/1.1 200 OK
{
    "code": 0,
    "message": "OK",
    "request_id": "{{request_id}}",
    "data": {}
}
(/code)

内容来源:TikTok API for Business 官方文档 · 本地归档

在接这个接口时卡住了?
Stuck wiring this API into production? We build ad-delivery tooling on these platforms — campaign automation, reporting pipelines, error-handling and migration between API versions.
联系我们 · Talk to us 每日平台更新简报 →