目录

Changes:getStartCursor

功能介绍

获取startCursor。

场景描述

获取Changes.subscribe需要使用的cursor值。

使用约束

Scope至少包含下面其中一个:
  • https://www.huawei.com/auth/drive.appdata
  • https://www.huawei.com/auth/drive.file
  • https://www.huawei.com/auth/drive
  • https://www.huawei.com/auth/drive.readonly
  • https://www.huawei.com/auth/drive.metadata
  • https://www.huawei.com/auth/drive.metadata.readonly

接口原型

承载协议

HTTP GET

接口方向

开发者服务器->华为云空间服务器

接口URL

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

数据格式

请求消息:Content-Type: application/json

响应消息:Content-Type: application/json

路径参数

无

查询参数

参数

是否必选

参数类型

描述

fields

是

string

采用[Partial-response格式],具体使用见公共说明。

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

无

请求示例

GET  https://driveapis.cloud.huawei.com.cn/drive/v1/changes/getStartCursor?fields=*    HTTP/1.1 
Content-Type: application/json 
Authorization: Bearer CV3PnPLZXyr9K2GV7RYZkF962JZvoEkMQhTho3QHQAPQUyma/lEyZskP/IMWrc7FvaeHivO7y0lyibI/fQvulBnTgtXArSVPsjaLKvYNkDsJSaIR2/sx+K40bYDWWpKFvJNKg2U47jRwz2mfiF3ortNk 
Cache-Control: no-cache

响应参数

状态码为200时:

参数

参数类型

描述

category

string

资源类型,固定为drive#startCursor。

startCursor

string

起始游标。

响应示例

{
            "category": "drive#startCursor",
            "startCursor": "238247332125117440"
}

常见错误码

错误码后4位为业务错误码,用于区分错误场景,其他业务错误码见状态码章节。

状态码

错误码

响应代码

描述

200

NA

-

成功。

500

21055002

OUTER_SERVICE_UNAVAILABLE

外部服务不可用。

500

21005006

SERVER_TEMP_ERROR

服务器临时错误。

403

21074033

AGREEMENT_NOT_SIGNED

用户还未签署华为云空间用户协议,请签署协议后再进行重试。

调用示例

   public static void main(String[] args) throws IOException {
        // 设置请求地址和用户认证令牌
        String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/changes/getStartCursor";
        String access_token = "CV5OUVN/e79TSba9Kaxlgx+TONKyYovWvre8BZM05oh6J51jBIbeYp0FRSuLcFBZoDaft0V/B+m+mPFf7MG3n8JmO8w3n6/K6zUI8I5/auSzdxv8GOdAPw==";
        // 获取startCursor
        JSONObject cursorInfo = changesGetStartCursor(url, access_token);
        System.out.println(cursorInfo.toJSONString());
    }

    private static JSONObject changesGetStartCursor(String url, String access_token) throws IOException {
        StringBuilder stringBuilder = new StringBuilder("");
        stringBuilder.append("?").append("fields=*");
        HttpGet httpGet = new HttpGet(url + stringBuilder);
        httpGet.setHeader("Authorization","Bearer " + access_token);
        CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet);

        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();
        }
    }