如何从Google Drive V3获取完整文件获取响应

时间:2016-12-14 08:08:58

标签: google-api google-drive-api

当我预先形成文件时,Google驱动器v2会默认返回完整的文件资源。获取。但是,当我针对V3发出相同的请求时,即使文档声明它应该返回文件资源,它也只返回部分文件资源。

GET /drive/v2/files/0B5pJkOVaKccEVEsybFA2WjJjQ1k?access_token={Token}

返回完整档案

{
  "mimeType": "text/plain", 
  "version": "416164", 
  "appDataContents": false, 
  "thumbnailLink": "https://lh3.googleusercontent.com/UE-d50Sda_j2pT1dzw8Ll1r7W2gYZNrofX2YS-VKG7Ykl4FAqe9NPPNPA3HX3PBdhQ8uow=s220", 
  "labels": {
    "restricted": false, 
    "starred": false, 
    "viewed": false, 
    "hidden": false, 
    "trashed": false
  }, 
  "explicitlyTrashed": false, 
  "lastModifyingUserName": "Linda Lawton", 
  "writersCanShare": true, 
  "owners": [
    {
      "picture": {
        "url": "https://lh5.googleusercontent.com/-a1CWlFnA5xE/AAAAAAAAAAI/AAAAAAAAdVM/sHkU9F-AwwQ/s64/photo.jpg"
      }, 
      "kind": "drive#user", 
      "displayName": "Linda Lawton", 
      "permissionId": "6030588225573437243", 
      "isAuthenticatedUser": true, 
      "emailAddress": "xxxxx@gmail.com"
    }
  ], 
  "id": "0B5pJkOVaKccEVEsybFA2WjJjQ1k", 
  "lastModifyingUser": {
    "picture": {
      "url": "https://lh5.googleusercontent.com/-a1CWlFnA5xE/AAAAAAAAAAI/AAAAAAAAdVM/sHkU9F-AwwQ/s64/photo.jpg"
    }, 
    "kind": "drive#user", 
    "displayName": "Linda Lawton", 
    "permissionId": "06030588225573437243", 
    "isAuthenticatedUser": true, 
    "emailAddress": "xxxxx@gmail.com"
  }, 
  "title": "deleteme.txt", 
  "ownerNames": [
    "Linda Lawton"
  ], 
  "etag": "\"dyf6dc5nFpQUIZ2nJvOu2LyLJk8/MTQ4MTU0MTI1NzI2MQ\"", 
  "parents": [
    {
      "isRoot": true, 
      "kind": "drive#parentReference", 
      "id": "0AJpJkOVaKccEUk9PVA", 
      "selfLink": "https://www.googleapis.com/drive/v2/files/0B5pJkOVaKccEVEsybFA2WjJjQ1k/parents/0AJpJkOVaKccEUk9PVA", 
      "parentLink": "https://www.googleapis.com/drive/v2/files/0AJpJkOVaKccEUk9PVA"
    }
  ], 
  "shared": false, 
  "originalFilename": "deleteme.txt", 
  "description": "Test Description", 
  "webContentLink": "https://drive.google.com/uc?id=0B5pJkOVaKccEVEsybFA2WjJjQ1k&export=download", 
  "editable": true, 
  "embedLink": "https://drive.google.com/file/d/0B5pJkOVaKccEVEsybFA2WjJjQ1k/preview?usp=drivesdk", 
  "markedViewedByMeDate": "1970-01-01T00:00:00.000Z", 
  "quotaBytesUsed": "150", 
  "modifiedDate": "2016-12-12T11:14:17.261Z", 
  "createdDate": "2016-12-12T11:14:17.261Z", 
  "md5Checksum": "8034035d0be478ab4e4c9bed279a5ff6", 
  "iconLink": "https://ssl.gstatic.com/docs/doclist/images/icon_10_text_list.png", 
  "kind": "drive#file", 
  "alternateLink": "https://drive.google.com/file/d/0B5pJkOVaKccEVEsybFA2WjJjQ1k/view?usp=drivesdk", 
  "copyable": true, 
  "modifiedByMeDate": "2016-12-12T11:14:17.261Z", 
  "downloadUrl": "https://doc-00-38-docs.googleusercontent.com/docs/securesc/1mngaurn1r7pdnvlih02e6t9l8me2de5/5h0plr5pqk919iiraojovqrovifi85g7/1481702400000/06030588225573437243/06030588225573437243/0B5pJkOVaKccEVEsybFA2WjJjQ1k?e=download&gd=true", 
  "userPermission": {
    "kind": "drive#permission", 
    "etag": "\"dyf6dc5nFpQUIZ2nJvOu2LyLJk8/-EUeXLzWA6FGgRjCErcDZHhfLzg\"", 
    "role": "owner", 
    "type": "user", 
    "id": "me", 
    "selfLink": "https://www.googleapis.com/drive/v2/files/0B5pJkOVaKccEVEsybFA2WjJjQ1k/permissions/me"
  }, 
  "spaces": [
    "drive"
  ], 
  "fileExtension": "txt", 
  "headRevisionId": "0B5pJkOVaKccEMW0yMitzcklkaWtFZ3FIS1l6Q2x5RGpKQkNjPQ", 
  "selfLink": "https://www.googleapis.com/drive/v2/files/0B5pJkOVaKccEVEsybFA2WjJjQ1k", 
  "fileSize": "150"
}

然而,当我对V3提出相同的请求时

GET /drive/v3/files/0B5pJkOVaKccEVEsybFA2WjJjQ1k?access_token={Token}

仅返回部分元数据

{
  "mimeType": "text/plain", 
  "kind": "drive#file", 
  "id": "0B5pJkOVaKccEVEsybFA2WjJjQ1k", 
  "name": "deleteme.txt"
}

我发现通过添加fields参数,我可以从V3请求其他参数。但是我无法找到一种方法来在一个请求中返回所有字段。

  

fields
选择器指定要包含在其中的字段子集   响应。
有关详细信息,请参阅部分响应部分   在性能提示文档中。用于提高性能。

它的一个get请求所以我不关心性能我只需要查看该文件的所有数据。

1 个答案:

答案 0 :(得分:19)

在文档中挖掘后,我设法找到comment

  

如果需要,请在字段选择中使用通配符   例如:fields = items / pagemap / *选择页面映射中的所有对象。

所以我试过了。

GET /drive/v3/files/0B5pJkOVaKccEVEsybFA2WjJjQ1k?access_token={Token}&fields=* 

果然它返回了完整的文件资源。

解决方案是将fields=*添加到请求中。我个人认为这应该是默认的。