Protocol | HTTP POST |
|---|---|
Direction | Developer server -> HUAWEI Drive server |
URL | https://driveapis.cloud.huawei.com.cn/drive/v1/channels/stop |
Data Format | Request: Content-Type: application/json Response: Content-Type: application/json |
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
quotaId | Optional | string | User identifier, which can contain a maximum of 40 characters. This parameter is used to restrict the maximum number of API calls for a single user. |
callback | Optional | string | Callback function used in JSONP requests. |
Request Header
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
Authorization | Mandatory | string | User authorization information, that is, the access token (AT). |
x-hw-trace-id | Optional | string | ID used for service tracing. |
x-hw-app-id | Optional | string | App ID. |
version | Optional | string | SDK version number. |
x-hw-terminal | Optional | string | Device model. |
x-hw-os | Optional | string | Device operating system. |
unionID | Optional | string | User's UnionID. |
User-Agent | Optional | string | App version number or app ID. |
x-hw-deviceUUID | Optional | string | UUID of the device. |
x-hw-deviceUDID | Optional | string | UDID of the device. |
x-hw-appPackageName | Optional | string | App package name. |
x-hw-network | Optional | string | Network type. The options include WiFi, 2G, 3G, 4G, 5G, and wire. |
Request Body
Parameter | Mandatory/Optional | Type | Description |
|---|---|---|---|
category | Mandatory | string | Resource type. The value is always api#channel. |
id | Mandatory | string | ID. |
resourceId | Mandatory | string | Resource ID, which identifies the resource being tracked on this channel. |
resourceUri | Optional | string | Version-specific identifier for the resource. |
userToken | Optional | string | A string that is sent to the target address along with each notification that is sent on this channel. |
expirationTime | Optional | integer | Date and time when the notification channel expires, expressed as a Unix timestamp, in milliseconds. File resources will expire within one day, while change resources will expire within one week. |
type | Optional | string | Type of the sending mechanism that is used for this channel. |
url | Optional | string | Callback address. |
POST https://driveapis.cloud.huawei.com.cn/drive/v1/channels/stop HTTP/1.1
Content-Type: application/json
Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaIR2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk
Cache-Control: no-cache
{
"category": "api#channel",
"id": "46TMU",
"resourceId": "MTIzMzIyMjQ1ODI0Nzc0MTgyNA",
"resourceUri": "https://drive.hicloud.com/drive/v1/changes?pageSize=10&cursor=238247332125117440&form=json",
"userToken": "Qeqqn",
"expirationTime": "1574674540000",
"type": "web_hook",
"url": "https://www.huawei.com"
} The last four digits in the result code indicate the service error code, which is used to differentiate error scenarios. For details about other service error codes, please refer to Status Codes.
Status Code | Result Code | Response Code | Description |
|---|---|---|---|
204 | NA | - | Success. |
400 | 21004001 | LACK_OF_PARAM | Input parameter is missing. Check the parameter list. |
400 | 21004002 | PARAM_INVALID | Parameter verification failed. Check the parameter list. |
400 | 21004003 | PARAM_VALUE_NOT_SUPPORT | Invalid parameter. Check the parameter list. |
403 | 21004035 | INSUFFICIENT_SCOPE | Scope verification failed. |
404 | 21004043 | CHANNEL_NOT_FOUND | No subscription channel is found. Check the passed parameters. |
403 | 21074033 | AGREEMENT_NOT_SIGNED | The HUAWEI Drive user agreement is not signed. Try again after the agreement is signed. |
public static void main(String[] args) throws IOException {
// Set the request URL and access token.
String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/channels/stop";
String access_token = "CV5OUVN/e79TSba9Kaxlgx+TONKyYovWvre8BZM05oh6J51jBIbeYp0FRSuLcFBZoDaft0V/B+m+mPFf7MG3n8JmO8w3n6/K6zUI8I5/auSzdxv8GOdAPw==";
// Stop tracking changes.
Boolean isStop = false;
isStop = channelsStop(url, access_token);
System.out.println(isStop);
}
private static Boolean channelsStop(String url, String access_token) throws IOException {
HttpPost httpPost = new HttpPost(url);
httpPost.setHeader("Authorization","Bearer " + access_token);
httpPost.setHeader("Content-Type", "application/json");
httpPost.setHeader("Accept", "application/json");
JSONObject jsonParam = new JSONObject();//You can get every value of jsonParam from ChangesSubscribe
jsonParam.put("resourceId", "MTIzOTA0Njg3ODM3MTUxMjcwNA");
jsonParam.put("category", "api#channel");
jsonParam.put("expirationTime", "1582191947000");
jsonParam.put("id", "46TMU");
jsonParam.put("pushToken", "Qeqqn");
jsonParam.put("type", "web_hook");
jsonParam.put("url", "https://www.huawei.com");
jsonParam.put("resourceUri", "https://drive.hicloud.com/drive/v3/changes?pageSize=100&cursor=299830100109593600&form=json&containers=drive");
StringEntity entity = new StringEntity(jsonParam.toString());
entity.setContentType("application/json");
httpPost.setEntity(entity);
CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost);
try {
if(response.getStatusLine().getStatusCode() == 204){
return true;
}
return false;
}finally {
response.close();
}
}