虎牙开放平台文档

虎牙账号互联接口说明

1. 授权接口(前端调用)

请求说明

url:https://udbapi.huya.com/open/oauth/authorize

HTTP请求方式:GET

请求参数

参数名参数类型含义是否必须
redirect_uristring回调地址必须
client_idstring应用id必须
statestring授权回调原样返回必须
scopestring请求用户授权时向用户显示的可进行授权的列表
如果要填写多个接口名称,请用英文逗号隔开
例如:scope=get_user_info,multi_platform_livestreaming
不传则默认请求对接口get_user_info进行授权
可选

例:https://udbapi.huya.com/open/oauth/authorize?client_id=xxxx&state=xxx&redirect_uri=xxxx

scope说明

取值含义备注
get_user_info获取用户基本信息默认获取
multi_platform_livestreaming多平台直播,希望将主播的直播流授权到虎牙平台此权限需要联系官方人员获取

第三方应用授权回调说明:

  • 302到redirect_uri,并携带参数code、state。
  • code(授权码)5分钟内有效,使用一次失效

例:https://xxxx.com/callback?code=xxx&state=xxx

2. 服务端code换token(后台调用)

请求说明

url:https://udbapi.huya.com/open/oauth/accessToken

HTTP请求方式:GET

请求参数

参数名参数类型含义
client_idstring应用id
client_secretstring私钥签名值
codestring授权code

请求响应

{ "code": 0, "msg": "成功", "data": { "access_token": "xxx", "open_id": "xxx", "union_id": "xxx", "refresh_token": "xxx" } }
字段名字段类型描述
codenumber返回码,0表示成功
access_tokenstring访问凭证,2小时内有效
open_idstring授权用户唯一标识,同一应用下同一用户唯一
union_idstring授权用户唯一标识,同一开发者账号下不同应用同一用户唯一(建议使用union_id作为用户唯一标识)
refresh_tokenstring用于刷新access_token,有效期30天

3. 获取用户信息(后台调用)

请求说明

url:https://udbapi.huya.com/open/oauth/userInfo

HTTP请求方式:GET

请求参数

参数名参数类型含义
client_idstring应用id
client_secretstring私钥签名值
access_tokenstring访问凭证
open_idstringURL编码后的open_id值
union_idstring是否需要返回union_id:1 - 需要返回,默认不返回

请求响应

{ "code": 0, "msg": "成功", "data": { "avatar": "xxx", "nick_name": "xxx", "gender": 0, "union_id": "xxx" } }
字段名字段类型描述
codenumber返回码,0表示成功
avatarstring头像
nick_namestring昵称
gendernumber性别:0 - 女,1 - 男,10 - 未知
union_idstring授权用户唯一标识,默认不返回

4. 刷新access_token(后台调用)

请求说明 url:https://udbapi.huya.com/open/oauth/refreshToken?client_id=xxx&client_secret=xxx&refresh_token=urlencode(xxx)

HTTP请求方式:GET

字段描述
client_id虎牙分配給第三方的应用id
client_secret虎牙分配給第三方的应用密钥
refresh_token用于刷新access_token,有效期30天,请求时请先进行url编码

请求响应

{ "code": 0, "msg": "成功", "data": { "access_token": "BgfQWsjEEAAIMQ67NcZU7u_jvTmr-XLwpJUSYFMb6qGA393gAPp9RwSlb0Sg-aq1Seo=", "expires_in": 7200, "refresh_token": "BwUljTBDHj90vfKyT_Pk8R53HpFmSmebx60WU6scc6FnfQ==", "open_id": "oplEQXES57kE5CYQ4dEyJf4u1lAsgbYAx+dRpP+g==" } }
字段类型描述
access_tokenstring接口调用凭证
expires_innumberaccess_token有效期,单位秒
refresh_tokenstring用于刷新access_token,有效期30天
open_idstring虎牙授权用户唯一标识

5. 错误码列表

错误码