目录

Channels:stop

功能介绍

删除订阅变更。

场景描述

调用channels.stop接口实现关闭监听某个Channel。

使用约束

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 POST

接口方向

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

接口URL

https://driveapis.cloud.huawei.com.cn/drive/v1/channels/stop

数据格式

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

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

路径参数

无

查询参数

参数

是否必选

参数类型

描述

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

参数

是否必选

参数类型

描述

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

回调地址。

请求示例

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

响应参数

状态码为204时无响应参数。

响应示例

无

常见错误码

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

状态码

错误码

响应代码

描述

204

NA

-

成功。

400

21004001

LACK_OF_PARAM

缺少入参,请检查参数列表。

400

21004002

PARAM_INVALID

参数校验失败,请检查参数列表。

400

21004003

PARAM_VALUE_NOT_SUPPORT

无效参数,请检查参数列表。

403

21004035

INSUFFICIENT_SCOPE

Scope校验失败。

404

21004043

CHANNEL_NOT_FOUND

找不到订阅的通道,请检查传入的参数是否有误。

403

21074033

AGREEMENT_NOT_SIGNED

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

调用示例

    public static void main(String[] args) throws IOException {
        // 设置请求地址和用户认证令牌
        String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/channels/stop";
        String access_token = "CV5OUVN/e79TSba9Kaxlgx+TONKyYovWvre8BZM05oh6J51jBIbeYp0FRSuLcFBZoDaft0V/B+m+mPFf7MG3n8JmO8w3n6/K6zUI8I5/auSzdxv8GOdAPw==";
        // 删除订阅变更
        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();
        }
    }