目录

Changes:subscribe

Function

Tracks changes.

Scenario

By calling the Changes.subscribe API, your app can track changes made to all files or folders of a user.

Restrictions

Prototype

Protocol

HTTP POST

Direction

Developer server -> HUAWEI Drive server

URL

https://driveapis.cloud.huawei.com.cn/drive/v1/changes/subscribe

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Path Parameters

None.

Query Parameters

Parameter

Mandatory/Optional

Type

Description

cursor

Mandatory

string

Cursor for the current page, which is obtained from nextCursor in the previous response.

fields

Optional

string

Fields in the request, which are in the partial response format. For details, please refer to Overview.

containers

Optional

string

Query scope. The value can be drive or applicationData. The default value is drive.

form

Optional

string

Media format.

prettyPrint

Optional

boolean

Indicates whether to return a response in a human-readable format.

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 Parameters

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

id

Mandatory

string

A unique string that identifies this channel.

userToken

Mandatory

string

A string that is sent to the target address along with each notification that is sent on this channel.

type

Mandatory

string

Type of the sending mechanism that is used for this channel. The value is web_hook.

url

Mandatory

string

Address where notifications are sent for 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.

Request Example

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"
}

Response Parameters

When the status code is 200:

Parameter

Type

Description

category

string

Resource type. The value is always api#channel.

id

string

ID.

resourceId

string

Resource ID, which identifies the resource being tracked on this channel.

resourceUri

string

Version-specific identifier for the resource.

userToken

string

A string that is sent to the target address along with each notification that is sent on this channel.

expirationTime

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

string

Type of the sending mechanism that is used for this channel.

url

string

Address where notifications are sent for this channel.

Response Example

{
            "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"
}

Common Result Codes

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

200

NA

-

Success.

400

21004000

PARAM_INVALID

The channel has been registered. Change the ID and try again.

400

21004001

LACK_OF_PARAM

Input parameter is missing. Check the parameter list.

400

21004002

PARAM_INVALID

Parameter verification failed. Check the parameter list.

403

21074033

AGREEMENT_NOT_SIGNED

The HUAWEI Drive user agreement is not signed. Try again after the agreement is signed.

500

21005006

SERVER_TEMP_ERROR

Server error.

Call Example

    public static void main(String[] args) throws IOException {
        // Set the request URL, cursor for the current page, and access token.
        String url = "https://10.33.18.209:9998/drive/v1/changes/subscribe";
        String cursor = "299830100109593600";// Obtain the cursor for the current page through the ChangesGetStartCursor API.
        String access_token = "CV5OUVN/e79TSba9Kaxlgx+TONKyYovWvre8BZM05oh6J51jBIbeYp0FRSuLcFBZoDaft0V/B+m+mPFf7MG3n8JmO8w3n6/K6zUI8I5/auSzdxv8GOdAPw==";
        // Track changes.
        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();
        }
    }