| 承载协议 | HTTP POST |
|---|---|
| 接口方向 | 开发者服务器->华为云空间服务器 |
| 接口URL | https://driveapis.cloud.huawei.com.cn/drive/v1/changes/subscribe |
| 数据格式 | 请求消息:Content-Type: application/json 响应消息:Content-Type: application/json |
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| cursor | 是 | string | 当前页游标,由前一个响应的nextCursor获取。 |
| fields | 否 | string | 采用[Partial-response格式],具体使用见公共说明。 |
| containers | 否 | string | 查询范围,可选值drive和applicationData。默认是drive |
| form | 否 | string | 媒体格式。 |
| prettyPrint | 否 | boolean | 是否以美观格式输出。 |
| quotaId | 否 | string | 用户标识,小于40个字符。用于限制单个用户的API访问数量。 |
| callback | 否 | string | JSONP的callback函数。 |
Request Header
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| Authorization | 是 | string | 用户鉴权信息 AccessToken(即AT) |
| x-hw-trace-id | 否 | string | 业务跟踪id。 |
| x-hw-app-id | 否 | string | 应用的appid。 |
| version | 否 | string | SDK版本。 |
| x-hw-terminal | 否 | string | 终端型号。 |
| x-hw-os | 否 | string | 终端操作系统类型。 |
| unionID | 否 | string | 用户的unionID。 |
| User-Agent | 否 | string | 应用版本号/appid。 |
| x-hw-deviceUUID | 否 | string | 设备UUID。 |
| x-hw-deviceUDID | 否 | string | 设备UDID。 |
| x-hw-appPackageName | 否 | string | 应用包名。 |
| x-hw-network | 否 | string | 网络类型,[WiFi, 2G, 3G, 4G, 5G, wire]。 |
Request Body
| 参数 | 是否必选 | 参数类型 | 描述 |
|---|---|---|---|
| id | 是 | string | 一个唯一ID,标识这个订阅通道。 |
| userToken | 是 | string | 发送消息通知时,回传给业务。 |
| type | 是 | string | 发送机制类型,web_hook。 |
| url | 是 | string | 发送通知的地址。 |
| expirationTime | 否 | integer | 通道的到期的日期和时间,以Unix时间戳表示,以毫秒为单位,File资源最长1天,Change资源最长1周。 |
POST https://driveapis.cloud.huawei.com.cn/drive/v1/changes/subscribe?cursor=238247332125117440&fields=* HTTP/1.1
Content-Type: application/json
Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaIR2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk
Cache-Control: no-cache
{
"url": "https://www.huawei.com",
"expirationTime": 1574674540000,
"id": "46TMU",
"type": "web_hook",
"userToken": "Qeqqn"
} 状态码为200时:
| 参数 | 参数类型 | 描述 |
|---|---|---|
| category | string | 资源类型,固定为api#channel。 |
| id | string | ID。 |
| resourceId | string | 资源ID,标识通道上正在监视的资源。 |
| resourceUri | string | 资源版本标识符。 |
| userToken | string | 发送消息通知时,回传给业务。 |
| expirationTime | integer | 通道的到期的日期和时间,以Unix时间戳表示,以毫秒为单位,File资源最长1天,Change资源最长1周。 |
| type | string | 类型。 |
| url | string | 回调地址。 |
{
"resourceId": "MTIzMzIyMjQ1ODI0Nzc0MTgyNA",
"category": "api#channel",
"expirationTime": 1574674540000,
"id": "46TMU",
"resourceUri": "https://drive.hicloud.com/drive/v3/changes?pageSize=10&cursor=238247332125117440&form=json",
"userToken": "Qeqqn"
} 错误码后4位为业务错误码,用于区分错误场景,其他业务错误码见状态码章节。
| 状态码 | 错误码 | 响应代码 | 描述 |
|---|---|---|---|
| 200 | NA | - | 成功。 |
| 400 | 21004000 | PARAM_INVALID | 通道已注册,请更换id再进行重试。 |
| 400 | 21004001 | LACK_OF_PARAM | 缺少入参,请检查参数列表。 |
| 400 | 21004002 | PARAM_INVALID | 参数校验失败,请检查参数列表。 |
| 403 | 21074033 | AGREEMENT_NOT_SIGNED | 用户还未签署华为云空间用户协议,请签署协议后再进行重试。 |
| 500 | 21005006 | SERVER_TEMP_ERROR | 服务器异常。 |
public static void main(String[] args) throws IOException {
// 设置请求地址,当前页游标和用户认证令牌
String url = "https://10.33.18.209:9998/drive/v1/changes/subscribe";
String cursor = "299830100109593600";// 通过ChangesGetStartCursor API获取当前页游标
String access_token = "CV5OUVN/e79TSba9Kaxlgx+TONKyYovWvre8BZM05oh6J51jBIbeYp0FRSuLcFBZoDaft0V/B+m+mPFf7MG3n8JmO8w3n6/K6zUI8I5/auSzdxv8GOdAPw==";
// 订阅变更
JSONObject changesInfo = changesSubscribe(url, access_token, cursor);
System.out.println(changesInfo.toJSONString());
}
private static JSONObject changesSubscribe(String url, String access_token, String cursor) throws IOException {
StringBuilder stringBuilder = new StringBuilder("");
stringBuilder.append("?").append("fields=*").append("&").append("cursor").append("=").append(cursor);
HttpPost httpPost = new HttpPost(url + stringBuilder);
httpPost.setHeader("Authorization","Bearer " + access_token);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Accept", "application/json");
JSONObject jsonParam = new JSONObject();
jsonParam.put("id", "46TMU");
jsonParam.put("type", "web_hook");//default value,can't change
jsonParam.put("pushToken", "Qeqqn");
jsonParam.put("url", "https://www.huawei.com");//Only support https.
jsonParam.put("expirationTime", 1582191947000);//optional.You can set it in 1-7 day or use default.Unix Time
StringEntity entity = new StringEntity(jsonParam.toString());
entity.setContentType("application/json");
httpPost.setEntity(entity);
CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost);
try {
HttpEntity responseEntity = response.getEntity();
String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
JSONObject jsonObject = (JSONObject) JSON.parse(ret);
EntityUtils.consume(responseEntity);
return jsonObject;
}finally {
response.close();
}
}