如何获取完整文件获得Google Drive V3的响应 [英] How to get full file get response from Google Drive V3

查看:79
本文介绍了如何获取完整文件获得Google Drive V3的响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我执行文件操作时,默认情况下,Google驱动器v2会默认返回完整的文件资源.但是,当我针对V3发出相同的请求时,即使文档指出它应返回文件资源,也仅返回部分文件资源.

The Google drive v2 seams to return a full file resource by default when I preform a file.Get. However when I make the same request against V3 even though the documentation states it should return a file resource it is only returning a partial file resource.

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发出相同的请求时

However when I make the same request against V3

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

它仅返回部分元数据

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

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

I have found that by adding the fields parameter I can request additional ones from V3. however I cant seam to find a way of returning all of the fields in one request.

fields
选择器,指定要包含在
有关更多信息,请参见部分响应部分 在性能提示"文档中.用于提高性能.

fields
Selector specifying a subset of fields to include in the response.
For more information, see the partial response section in the Performance Tips document. Use for better performance.

它是一个get请求,因此我不关心性能,我只需要查看此文件的所有数据即可.

Its one get request so I am not concerned with performance I just need to see all the data for this file.

推荐答案

在文档中进行深入研究后,我设法找到了

After digging around in the documentation I managed to find a comment.

如果需要,在字段选择中使用通配符.
例如,fields = items/pagemap/*选择页面地图中的所有对象.

Use wildcards in field selections, if needed.
For example: fields=items/pagemap/* selects all objects in a pagemap.

所以我尝试了这个.

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

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

Sure enough it returned the full File resource.

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

Solution was to add fields=* to the request. Personally I think this should be default.

这篇关于如何获取完整文件获得Google Drive V3的响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆