获取授权小程序接口调用凭据V2

收藏
我的收藏

接口说明

该接口用于获取授权小程序接口调用凭据。

授权小程序接口调用凭据 authorizer_access_token 是服务商代授权小程序调用开放接口的必要参数。

使用限制

  • authorizer_access_token 有效期 2 小时。
  • 通过该接口获取到的 authorizer_access_token 为V2版authorizer_access_token,与 V1 版 authorizer_access_token 不可混用;
  • 各 OpenAPI  使用的 authorizer_access_token 类型需要参考接口文档里 access-token 参数的说明,只有特别标注使用该接口获取到的 authorizer_access_token 才可以使用本接口获取到的 authorizer_access_token 进行调用;
  • 后续新增的小程序相关接口都只支持通过 V2 版 authorizer_access_token 进行调用;
  • 存量的接口会逐步推出和V2 版 authorizer_access_token 相匹配的新接口,存量接口仍可用,但建议开发者迁移使用新接口;

基本信息

名称描述
HTTP URL
https://open.douyin.com/api/tpapp/v2/auth/get_auth_token/
HTTP Method
GET
Scope
thirdparty.dev.auth

请求头

名称字段类型是否必填示例描述
access-tokenStringclt.05efxxxxxxxxxqPf9pWBo0IKVHmSKce5EvKX

请求参数

Query

名称字段类型是否必填示例描述
grant_typeString

获取方式

通过授权码方式获取填写固定字符串:app_to_tp_authorization_code

通过刷新令牌方式获取填写固定字符串:app_to_tp_refresh_token

authorization_codeString

授权码

通过授权码方式获取必填

authorizer_refresh_tokenString

刷新令牌 authorizer_refresh_token

通过刷新令牌方式获取必填

请求示例

curl --location 'https://open.douyin.com/api/tpapp/v2/auth/get_auth_token?grant_type=app_to_tp_authorization_code&authorization_code=xxxxxxxxxxxx' \
--header 'access-token: clt.eafxxxxxxxxxxxxxxxxxxZcVHzh79g1qS2Tol9kCT' 

响应参数

Body

名称字段类型是否必填示例描述
err_msgString
err_noInt32
log_idString

响应示例

正常响应示例

{
  "err_no": 0,
  "log_id": "2023101312022744C2A2666DB7BC00832B",
  "data": {
    "authorizer_access_token": "isvact.5dafax837bb9937cdxxxxxx200fO2Eh5YgvG4pFmj6nSf8NGr6j8Yfg",
    "authorizer_appid": "xxxxxx",
    "authorizer_refresh_token": "isvrft.d016bb817070xxxxxtUS9BNtfJ174uhFNFUnW",
    "expires_in": 7200,
    "refresh_expires_in": 2592000,
    "authorize_permission": [
      {
        "category": "开发管理权限",
        "description": "帮助小程序进行基础功能开发及配置开发所需信息",
        "id": 1
      },
      {
        "category": "基本信息设置权限",
        "description": "帮助小程序管理名称、头像、简介、服务类目等信息",
        "id": 2
      }
    ]
  },
  "err_msg": ""
}

异常响应示例

{
  "err_no": 28001008,
  "err_msg": "access_token过期,请刷新或重新授权",
  "log_id": "202402231601203A85A7BDF409E505D210"
}

错误码

http状态码错误码错误码描述排查建议
20040001
参数错误
20040002
缺少参数
20040003
找不到相关第三方小程序应用
20040004
找不到相关授权小程序
20040018
第三方小程序应用 authorization_code 不正确或者已过期
20040040
无效的 grant_type
20040045
生成 token 失败,请重试
20028001008
access-token过期