目录

HistoryVersions:list

Function

Lists the historical versions of a file.

Scenario

By calling the HistoryVersions.list API, your app can list the historical versions of a file.

Restrictions

Prototype

Protocol

HTTP GET

Direction

Developer server -> HUAWEI Drive server

URL

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

Data Format

Request: Content-Type: application/json

Response: Content-Type: application/json

Path Parameters

Parameter

Mandatory/Optional

Type

Description

fileId

Mandatory

string

File ID.

Query Parameters

Parameter

Mandatory/Optional

Type

Description

pageSize

Optional

integer

Maximum number of results to return per page. The default value is 100. The value ranges from 1 to 100. Note: It is possible that partial or empty result pages are returned before the end of the result list has been reached.

cursor

Optional

string

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

fields

Mandatory

string

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

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

None.

Request Example

GET 
https://driveapis.cloud.huawei.com.cn/drive/v1/files/BjYqWC-dH6-gcN6p5zxhI4I7Z1wtrR-po/historyVersions?fields=* HTTP/1.1
Accept: application/json
Authorization: Bearer
CgB6e3x9Bjh6m9tm8OB0GXjeMWk0m4pVnLmwteDNWXOKPhh0/tjwtIy6Q+OscvD7zhdrElYD0Rak6xA7dI4BM3GSQTuUgFK6ZwFk7K/fjJS5vB7JFmV3
Cache-Control: no-cache

Response Parameters

When the status code is 200:

Parameter

Type

Description

category

string

Resource type. The value is always drive#permissionList.

nextCursor

string

Cursor for the next page. If nextCursor is empty, there is no next page.

historyVersions[]

list

List of historical file versions.

historyVersions.category

string

Historical version category. The value is always drive#historyVersion.

historyVersions.id

string

ID of a historical version.

historyVersions.mimeType

string

MIME type of the file.

historyVersions.editedTime

string

Last time when a historical version is modified.

historyVersions.keepPermanent

boolean

Indicates whether a historical version will be permanently kept.

historyVersions.lastEditor.category

string

User type. The value is always drive#user.

historyVersions.lastEditor.displayName

string

Display name of the user.

historyVersions.lastEditor.profilePhotoLink

string

Link to the user's profile picture, which is not returned by default.

historyVersions.lastEditor.me

boolean

Indicates whether the user is the requesting user.

historyVersions.lastEditor.permissionId

string

Permission ID.

historyVersions.lastEditor.userAccount

string

Account of the user, which is not returned by default.

historyVersions.originalFilename

string

Original file name of a historical version. This parameter specifies the file name used when the file entity is created for the first time. The value can be obtained only when the metadata involves file entity updates.

historyVersions.size

integer

File size.

historyVersions.sha256

string

SHA-256 value for the file.

Response Example

HTTP/1.1 200 OK 
{
   "historyVersions": [
      {
   "editedTime": "2020-05-15T06:21:11Z",
   "size": 1,
   "sha256": "4dcdc56b396adb1b68ad3257f2f9679f0b289ff003bbf3251bc7c8956c731849",
   "lastEditor": {
  "permissionId": "239606675785384320",
  "displayName": "*******3121@**3.com",
  "me": true,
  "category": "drive#user"
     },
   "id": "362821313154268928.362821313154268929",
   "mimeType": "text/plain",
   "category": "drive#historyVersion",
   "keepPermanent": false
      }
     ],
    "category": "drive#historyVersionList"
}

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

21004002

PARAM_INVALID

Invalid input parameter. Check the parameter list.

403

21074033

AGREEMENT_NOT_SIGNED

HUAWEI Drive user agreement not signed.

403

21084031

DATA_MIGRATINT

The security policy is being updated. Please wait until the update is complete.

403

21084038

OUTER_SERVICE_ERROR

External service error.

403

21094038

OUTER_SERVICE_ERROR

External service error.

404

21084041

CONTENT_NOT_FOUND

The content is not found.

500

21085002

OUTER_SERVICE_UNAVAILABLE

External service is unavailable.

Call Example

	public static void main(String[] args) throws IOException {
        // Set the request URL, file ID, permission ID, and access token.
        String url = "https://driveapis.cloud.huawei.com.cn/drive/v1/files";
        String fileId = "AB0tr6O8DTQAguUs3yPFt3wQ5SDfLg04A";//Your own fileId
        String access_token = "CV5T547SEXpRlyuxqvz+PnRCtnVu784+OEIXmXAafKC+ifA3eJRnM0Ttsv20bJCkrcA+FNi4bU4nKcbERpQxlkMLQ6/Xt1iEQJYrFMyamnnI9JUV+jz4cQ==";
        // List the historical versions of a file.
        JSONObject historyVersionsInfo = historyVersionsList(url, access_token, fileId);
        System.out.println(historyVersionsInfo.toJSONString());
    }

    private static JSONObject historyVersionsList(String url, String access_token, String fileId) throws IOException {
        StringBuilder stringBuilder = new StringBuilder("");
        stringBuilder.append("/").append(fileId).append("/").append("historyVersions");
        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();
        }
    }