调用GetDeviceCredential查询设备的访问凭证。
使用限制
本接口的单用户QPS限制为500次/秒。超过限制,API调用会被限流,这可能会影响您的业务,请合理调用。更多信息,请参见QPS限制。
说明 每成功调用一次GetDeviceCredential接口,都会计算为一次消息TPS,从而影响您的计费。详细信息,请参见计费说明。
调试
您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。
请求参数
名称 | 类型 | 是否必选 | 示例值 | 描述 |
---|---|---|---|---|
Action | String | 是 | GetDeviceCredential | 系统规定参数。取值:GetDeviceCredential。 |
ClientId | String | 是 | GID_test@@@test | 需要查询访问凭证的设备的Client ID。 |
InstanceId | String | 是 | post-cn-0pp12gl**** | 云消息队列 MQTT 版实例的ID,一定要和客户端实际使用的实例ID匹配。您可以在控制台实例详情页面获取该ID。 |
返回数据
名称 | 类型 | 示例值 | 描述 |
---|---|---|---|
RequestId | String | E4581CCF-62AF-44D9-B5B4-D1DQDC0E**** | 公共参数,每个请求的ID都是唯一的。 |
DeviceCredential | Object | 设备的访问凭证信息。 |
|
UpdateTime | Long | 1605541382000 | 设备访问凭证上一次更新的毫秒时间戳。 |
DeviceAccessKeyId | String | DC.Z5fXh9sRRVufyLi6wo**** | 设备的AccessKey ID。 |
CreateTime | Long | 1605541382000 | 设备访问凭证创建的毫秒时间戳。 |
InstanceId | String | post-cn-0pp12gl**** | 云消息队列 MQTT 版实例的ID。 |
DeviceAccessKeySecret | String | DC.BJMkn4eMQJK2vaApTS**** | 设备的AccessKey Secret。 |
ClientId | String | GID_test@@@test | 设备的Client ID。 |
示例
请求示例
http(s)://onsmqtt.cn-hangzhou.aliyuncs.com/?Action=GetDeviceCredential
&ClientId=GID_test@@@test
&InstanceId=post-cn-0pp12gl****
&RegionId=cn-hangzhou
&<公共请求参数>
正常返回示例
XML
格式
HTTP/1.1 200 OK
Content-Type:application/xml
<GetDeviceCredentialResponse>
<RequestId>E4581CCF-62AF-44D9-B5B4-D1DQDC0E****</RequestId>
<DeviceCredential>
<InstanceId>post-cn-0pp12gl****</InstanceId>
<DeviceAccessKeySecret>DC.BJMkn4eMQJK2vaApTS****</DeviceAccessKeySecret>
<CreateTime>1605541382000</CreateTime>
<UpdateTime>1605541382000</UpdateTime>
<DeviceAccessKeyId>DC.Z5fXh9sRRVufyLi6wo****</DeviceAccessKeyId>
<ClientId>GID_test@@@test</ClientId>
</DeviceCredential>
</GetDeviceCredentialResponse>
JSON
格式
HTTP/1.1 200 OK
Content-Type:application/json
{
"RequestId" : "E4581CCF-62AF-44D9-B5B4-D1DQDC0E****",
"DeviceCredential" : {
"InstanceId" : "post-cn-0pp12gl****",
"DeviceAccessKeySecret" : "DC.BJMkn4eMQJK2vaApTS****",
"CreateTime" : 1605541382000,
"UpdateTime" : 1605541382000,
"DeviceAccessKeyId" : "DC.Z5fXh9sRRVufyLi6wo****",
"ClientId" : "GID_test@@@test"
}
}
错误码
HttpCode | 错误码 | 错误信息 | 描述 |
---|---|---|---|
400 | ApplyTokenOverFlow | You have applied for tokens too many times. Please try again later. | 申请 Token 频率过高,系统限流,请重试。 |
400 | CheckAccountInfoFailed | An error occurred while checking the account information by the STS token. | 解析 STS Token 账号信息失败。 |
400 | InstancePermissionCheckFailed | An error occurred while validating the permissions of the instance. Please verify the account that created the instance and its permissions settings. | 实例权限校验失败,请确认 MQTT 实例的所属关系以及授权策略。 |
400 | ParameterCheckFailed | An error occurred while validating the parameters. The parameters may be missing or invalid. | 参数校验失败,可能缺失或者传入值非法。 |
400 | PermissionCheckFailed | An error occurred while validating the resource permissions. Please check the account that created the instance, topic, and GroupId, and check their permission settings. | 资源权限校验失败,请检查实例、Topic 和 Group ID 的所属权限和授权策略。 |
400 | InvalidParameter.%s | An error occurred while validating the parameter. The parameter may be missing or invalid. | 参数校验失败,可能缺失或者传入值非法。 |
500 | InternalError | An error occurred while processing your request. Try again later. | MQTT 后端服务异常,请重试。 |
500 | SystemOverFlow | An error occurred while processing your request. Please try again. | 系统限流,请重试。 |
404 | ApiNotSupport | The specified API is not supported. | 当前接口不支持,请检查。 |
访问错误中心查看更多错误码。