获取 user_access_token
Error: 本接口已成为历史版本,不推荐使用。请使用最新版本:获取 user_access_token
。
根据登录预授权码 返回 code 获取 user_access_token。
Tip: - 为了让流程更加规范,本接口不再返回用户信息,只返回token相关的字段。如需用户信息,请通过 获取用户信息接口获取数据。
- user_access_token 有效期为 2 小时左右,具体剩余有效期可通过当前接口返回的 expires_in 参数获取。如果 user_access_token 过期可以刷新 user_access_token。当前接口返回结果中包含用于刷新 user_access_token 的 refresh_token 参数,注意该参数也存在有效期(30 天左右),具体剩余有效期可通过返回的 refresh_expires_in 参数获取。
请求
| 项目 | 值 |
|---|---|
| HTTP URL | https://open.feishu.cn/open-apis/authen/v1/oidc/access_token |
| HTTP Method | POST |
| 接口频率限制 | 1000 次/分钟、50 次/秒 |
| 支持的应用类型 | custom,isv |
| 权限要求 调用该 API 所需的权限。开启其中任意一项权限即可调用 | 无 |
请求头
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
| Authorization | string | 是 | app_access_token 值格式:"Bearer access_token" 示例值:"Bearer a-7f1bcd13fc57d46bac21793a18e560" 了解更多:如何选择与获取 access token |
| Content-Type | string | 是 | 固定值:"application/json; charset=utf-8" |
请求体
| 名称 | 类型 | 必填 | 描述 |
|---|---|---|---|
grant_type | string | 是 | 授权类型,固定值 示例值:"authorization_code" |
code | string | 是 | 登录预授权码,调用登录预授权码 获取code 示例值:"xMSldislSkdK" |
请求体示例
json
{
"grant_type": "authorization_code",
"code": "xMSldislSkdK"
}响应
响应体
| 名称 | 类型 | 描述 |
|---|---|---|
code | int | 错误码,非 0 表示失败 |
msg | string | 错误描述 |
data | token_info | - |
└ access_token | string | 字段access_token即user_access_token,用于获取用户资源和访问某些open api |
└ refresh_token | string | 刷新user_access_token时使用的 refresh_token |
└ token_type | string | token 类型,固定值 |
└ expires_in | int | user_access_token有效期,单位: 秒,有效时间两个小时左右,需要以返回结果为准 |
└ refresh_expires_in | int | refresh_token有效期,单位: 秒,一般是30天左右,需要以返回结果为准 |
└ scope | string | 用户授予app的权限全集 |
响应体示例
json
{
"code": 0,
"msg": "success",
"data": {
"access_token": "u-5Dak9ZAxJ9tFUn8MaTD_BFM51FNdg5xzO0y010000HWb",
"refresh_token": "ur-6EyFQZyplb9URrOx5NtT_HM53zrJg59HXwy040400G.e",
"token_type": "Bearer",
"expires_in": 7199,
"refresh_expires_in": 2591999,
"scope": "auth:user.id:read bitable:app"
}
}错误码
| HTTP状态码 | 错误码 | 描述 | 排查建议 |
|---|---|---|---|
| 200 | 20001 | Invalid request. Please check request param | 请检查请求参数 |
| 200 | 20002 | The app_id or app_secret passed is incorrect. Please check the value | 检查app_id和密钥是否正确 |
| 200 | 20003 | The code passed is invalid. Please note that the code could only be used once | 登录预授权码的有效期是 5 分钟,且只能被使用一次。请检查登录预授权码是否被重复使用或过期 |
| 200 | 20004 | The code passed has expired. Please generate a new one | 过期code,请重新生成 |
| 200 | 20007 | Failed to generate a user access token. Please try again | 请检查参数是否有效,重试 |
| 200 | 20008 | User not exist | 用户不存在,换有效帐号 |
| 200 | 20013 | The tenant access token passed is invalid. Please check the value | 检查tenant_access_token是否有效 |
| 200 | 20014 | The app access token passed is invalid. Please check the value | 检查app_access_token是否有效 |
| 200 | 20021 | User resigned | 用户离职,请使用有效帐号 |
| 200 | 20022 | User frozen | 用户冻结,请使用有效帐号 |
| 200 | 20023 | User not registered | 用户未注册,请使用有效帐号 |
| 200 | 20024 | App id in user_access_token or refresh_token diff with app id in app_access_token or tenant_access_token. Please keep the app id consistent | 请检查生成两个token的app是否为同一个 |
| 200 | 20025 | Lack of app_id or app_secret in request | 缺失app_id或app_secret,请检查参数 |
| 200 | 20028 | Invalid app id | 无效app_id,请检查参数 |
| 200 | 20029 | Invalid redirect uri | redirect_uri 无效。排查方案: 1. 确保 Authorization 取值正确。例如,实际开发的应用 A,但调用 API 时却使用了应用 B 的 app_access_token。 2. 确保获取登录授权码 code 时,设置的回调地址 redirect_uri 参数,已配置到开发者后台 > 应用详情页 > 安全设置 > 重定向 URL。 关于该报错的详细解决方案,参见如何解决授权免登页面 20029 错误。 |
| 200 | 20035 | The app_id or app_secret passed is incorrect. Please check the value | 无效app_id 或 app_secret,请检查参数 |
| 200 | 20036 | The grant_type passed is not supported | 无效grant_type,请与接口要求保持一致 |
| 200 | 20039 | The user access token is not found. Please check the value | 查询不到user_access_token,请传有效参数 |
| 200 | 20042 | App disabled | app不可用,请检查app状态 |
| 200 | 20046 | Brand inconsistency | 应用品牌和域名品牌不一致,请保证feishu应用在feishu域名下使用,lark类似 |
