文档管理中心
API参考云空间服务RESTCommentsComments:create

Comments:create

功能介绍

创建文件评论。

场景描述

您的应用可以通过Comments.create接口创建文件评论。

使用约束

  • 只有writer/commenter/owner角色可以创建文件评论。
  • fields填*时,drive#comments 结构中replies不返回。
  • Scope至少包含下面其中一个:
    • https://www.huawei.com/auth/drive.file
    • https://www.huawei.com/auth/drive

接口原型

承载协议

HTTP POST

接口方向

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

接口URL

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

数据格式

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

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

路径参数

展开

参数

是否必选

参数类型

描述

fileId

string

文件ID。

查询参数

展开

参数

是否必选

参数类型

描述

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

展开

参数

是否必选

参数类型

描述

description

string

评论的内容。

quotedContent.mimeType

string

内容类型。

quotedContent.content

string

引用的内容。

position

string

位置,JSON格式,JSON按Anchor类型的定义校验。

请求示例

收起
自动换行
深色代码主题
复制
  1. POST 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#comment。

id

string

评论id。

createdTime

string

评论创建时间。

editedTime

string

评论修改时间。

creator.category

string

类型,固定为drive#user。

creator.displayName

string

用户显示名。

creator.profilePhotoLink

string

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

creator.me

boolean

是否是我。

creator.permissionId

string

权限id。

creator.userAccount

string

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

description

string

评论描述。

htmlDescription

string

HTML评论描述。

deleted

boolean

评论是否已删除。

resolved

boolean

是否已解决。

quotedContent.mimeType

string

内容类型。

quotedContent.content

string

引用的内容。

position

string

位置。

replies[]

list

回复列表。

replies.category

string

类型,固定为drive#reply。

replies.id

string

回复id。

replies.createdTime

string

回复创建时间。

replies.editedTime

string

回复修改时间。

replies.creator.category

string

类型,固定为drive#user。

replies.creator.displayName

string

用户显示名。

replies.creator.profilePhotoLink

string

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

replies.creator.me

boolean

是否是我。

replies.creator.permissionId

string

权限id。

replies.creator.userAccount

string

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

replies.htmlDescription

string

html内容。

replies.description

string

内容。

replies.deleted

boolean

评论回复是否已删除。

replies.operate

string

操作。

响应示例

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

常见错误码

错误码后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 commentInfo = commentCreateContent(url, access_token, fileId);
  8. System.out.println(commentInfo.toJSONString());
  9. }
  10. private static JSONObject commentCreateContent(String url, String access_token, String fileId) throws IOException {
  11. StringBuilder stringBuilder = new StringBuilder("");
  12. stringBuilder.append(fileId).append("/").append("comments");
  13. stringBuilder.append("?").append("fields=*");
  14. HttpPost httpPost = new HttpPost(url + stringBuilder);
  15. httpPost.setHeader("Authorization", "Bearer " + access_token);
  16. httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
  17. httpPost.setHeader("Accept", "application/json");
  18. JSONObject jsonParam = new JSONObject();
  19. jsonParam.put("description", "2020/02/23 11:20");
  20. JSONObject jsonObject = new JSONObject();
  21. jsonObject.put("mimeType", "text/html");
  22. jsonObject.put("content", "2222");
  23. jsonParam.put("quotedContent", jsonObject);
  24. StringEntity entity = new StringEntity(jsonParam.toString());
  25. httpPost.setEntity(entity);
  26. CloseableHttpResponse response = HttpClientUtil.getClient().execute(httpPost);
  27. try {
  28. HttpEntity responseEntity = response.getEntity();
  29. String ret = responseEntity != null ? EntityUtils.toString(responseEntity) : null;
  30. JSONObject jsonObject1 = (JSONObject) JSON.parse(ret);
  31. EntityUtils.consume(responseEntity);
  32. return jsonObject1;
  33. } finally {
  34. response.close();
  35. }
  36. }
在 API参考 中进行搜索
请输入您想要搜索的关键词