管理中心
我的

Comments:list

功能介绍

列举评论列表。

场景描述

您的应用可以通过Comments.list接口获取到文件的评论列表。

使用约束

  • 只有reader/writer/commenter/owner可以查看。
  • fields填*时,drive#comments 结构中replies不返回。
  • Scope至少包含下面其中一个:
    • https://www.huawei.com/auth/drive.file
    • https://www.huawei.com/auth/drive
    • https://www.huawei.com/auth/drive.readonly

接口原型

承载协议

HTTP GET

接口方向

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

接口URL

https://driveapis.cloud.huawei.com.cn/drive/v1/files/{fileId}/comments

数据格式

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

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

路径参数

展开

参数

是否必选

参数类型

描述

fileId

是

string

文件ID。

查询参数

展开

参数

是否必选

参数类型

描述

pageSize

否

integer

每页返回的个数,默认是100,可接受值1-100。注意在到达最后的列表之前,实际有可能返回部分或者空结果。

cursor

否

string

当前页游标,由前一个响应的nextCursor获取。

startEditedTime

否

string

起始变更时间。

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

无

请求示例

收起
自动换行
深色代码主题
复制
  1. GET https://driveapis.cloud.huawei.com.cn/drive/v1/files/AADUyBNACuoBSKfx8gh50-ASp_fyGgrsA/comments?fields=* HTTP/1.1
  2. Accept: application/json
  3. Cache-Control: no-cache
  4. Authorization: Bearer CF3NTYZSs7MRmxWyj8ssonQQxDgSPAjnDvrf+91NrpN22LdUrMA30A5Kzz0mf55sWao7e7VeLrmjQ0z2OmwPWlt3S00/L1BJppbTFhIgWb74ZBK8CFImUA==

响应参数

状态码为200时:

展开

参数

参数类型

描述

category

string

类型,固定为drive#commentList。

nextCursor

string

下一页游标,为空表示最后一页。

comments[]

list

评论列表。

comments.category

string

类型,固定为drive#comment。

comments.id

string

评论id。

comments.createdTime

string

评论创建时间。

comments.editedTime

string

评论修改时间。

comments.creator.category

string

类型,固定为drive#user。

comments.creator.displayName

string

用户显示名。

comments.creator.profilepPhotoLink

string

用户头像链接(默认不返回)。

comments.creator.me

boolean

是否是我。

comments.creator.permissionId

string

权限id。

comments.creator.userAccount

string

帐号名称(默认不返回)。

comments.description

string

评论描述。

comments.htmlDescription

string

HTML评论描述。

comments.deleted

boolean

评论是否已删除。

comments.resolved

boolean

是否已解决。

comments.quotedContent.mimeType

string

内容类型。

comments.quotedContent.content

string

引用的内容。

comments.position

string

位置。

comments.replies[]

list

回复列表。

comments.replies.category

string

类型,固定为drive#reply。

comments.replies.id

string

回复id。

comments.replies.createdTime

string

回复创建时间。

comments.replies.editedTime

string

回复修改时间。

comments.replies.creator.category

string

类型,固定为drive#user。

comments.replies.creator.displayName

string

用户显示名。

comments.replies.creator.profilePhotoLink

string

用户头像链接(默认不返回)。

comments.replies.creator.me

boolean

是否是我。

comments.replies.creator.permissionId

string

权限id。

comments.replies.userAccount

string

帐号名称(默认不返回)。

comments.replies.htmlDescription

string

html内容。

comments.replies.description

string

内容。

comments.replies.deleted

boolean

评论回复是否已删除。

comments.replies.operate

string

操作。

响应示例

收起
自动换行
深色代码主题
复制
  1. {
  2. "category": "drive#commentList",
  3. "nextCursor": "string",
  4. "comments": [
  5. {
  6. "category": "drive#comment",
  7. "id": "string",
  8. "createdTime": "2020-02-19T14:44:40.660Z",
  9. "editedTime": "2020-02-19T14:44:40.661Z",
  10. "creator": {
  11. "category": "drive#user",
  12. "displayName": "string",
  13. "profilePhotoLink": "string",
  14. "me": true,
  15. "permissionId": "string",
  16. "userAccount": "string"
  17. },
  18. "description": "string",
  19. "htmlDescription": "string",
  20. "deleted": true,
  21. "resolved": true,
  22. "quotedContent": {
  23. "mimeType": "string",
  24. "content": "string"
  25. },
  26. "position": "string",
  27. "replies": [
  28. {
  29. "category": "drive#reply",
  30. "id": "string",
  31. "createdTime": "2020-02-19T14:44:40.661Z",
  32. "editedTime": "2020-02-19T14:44:40.661Z",
  33. "creator": {
  34. "category": "drive#user",
  35. "displayName": "string",
  36. "profilePhotoLink": "string",
  37. "me": true,
  38. "permissionId": "string",
  39. "userAccount": "string"
  40. },
  41. "htmlDescription": "string",
  42. "description": "string",
  43. "deleted": true,
  44. "operate": "string"
  45. }
  46. ]
  47. }
  48. ]
  49. }

常见错误码

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

展开

状态码

错误码

响应代码

描述

200

NA

-

成功。

400

21004001

LACK_OF_PARAM

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

400

21004002

PARAM_INVALID

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

403

21004032

SERVICE_NOT_SUPPORT

服务不支持。

403

21004035

INSUFFICIENT_SCOPE

Scope校验失败。

403

21004036

INSUFFICIENT_PERMISSION

角色权限不足。

500

21005006

SERVER_TEMP_ERROR

服务器异常。

403

21074033

AGREEMENT_NOT_SIGNED

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

403

21084031

DATA_MIGRATING

正处于安全策略更新, 请等待安全策略更新完成。

500

21085002

OUTER_SERVICE_UNAVAILABLE

外部服务不可用。

500

21085006

SERVER_TEMP_ERROR

服务器异常。

调用示例

收起
自动换行
深色代码主题
复制
  1. public static void main(String[] args) throws IOException {
  2. // 设置请求地址,文件ID和用户认证令牌
  3. String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/files";
  4. String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A";
  5. String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ==";
  6. // 列举评论列表
  7. JSONObject commentsInfo = commentsList(url, access_token, fileId);
  8. System.out.println(commentsInfo.toJSONString());
  9. }
  10. private static JSONObject commentsList(String url, String access_token, String fileId) throws IOException {
  11. StringBuilder stringBuilder = new StringBuilder("");
  12. stringBuilder.append("/").append(fileId).append("/").append("comments");
  13. stringBuilder.append("?").append("fields=*");
  14. stringBuilder.append("&").append("prettyPrint=true");
  15. //stringBuilder.append("&").append("form=json");
  16. HttpGet httpGet = new HttpGet(url + stringBuilder);
  17. httpGet.setHeader("Authorization","Bearer " + access_token);
  18. RequestConfig requestConfig = RequestConfig.custom()
  19. .setConnectTimeout(50000).setConnectionRequestTimeout(10000)
  20. .setSocketTimeout(50000).build();
  21. httpGet.setConfig(requestConfig);
  22. CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpGet);
  23. try {
  24. HttpEntity responseEntity = response.getEntity();
  25. String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
  26. JSONObject jsonObject = (JSONObject) JSON.parse(ret);
  27. EntityUtils.consume(responseEntity);
  28. return jsonObject;
  29. }finally {
  30. response.close();
  31. }
  32. }