2016-12-14 61 views
4

Google Drive v2接口在默認情況下會返回完整的文件資源,當我執行一個文件時。獲取。但是,即使文檔指出它應該返回一個文件資源,它只會返回一個部分文件資源,但當我對V3發出相同的請求時。如何從Google Drive 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": "[email protected]" 
    } 
    ], 
    "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": "[email protected]" 
    }, 
    "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" 
} 

我發現,通過加入t他領域參數我可以從V3請求額外的參數。但我不能縫隙找到一種方式來返回一個請求中的所有字段。

字段
選擇器指定要包含在 響應中的字段的子集。
有關更多信息,請參閱「性能提示」文檔中的部分響應部分 。用於更好的性能。

它的一個獲取請求,所以我不關心性能我只需要查看此文件的所有數據。

回答

13

在文檔中挖掘後,我設法找到了一個comment

如果需要,在字段選擇中使用通配符。
例如:fields = items/pagemap/*選擇頁面地圖中的所有對象。

所以我試了這個。

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

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

解決方案是將fields=*添加到請求中。我個人認爲這應該是默認的。

+0

這是一個嘗試提高性能。隨着文件資源發展到包含越來越多的屬性,其中一些屬性可能需要昂貴的獲取或獲取,或者可能堵塞Googfle的管道,因此迫使開發人員僅指定她需要的應用程序的屬性是有意義的。 – pinoyyid

+0

我獲得1000行Google Analytics數據,目前可以包含7個維度和10個指標。而且你認爲驅動團隊擔心單個元數據的獲取將會返回。即使他們添加了100個新字段,我也不認爲Google會感受到它。 – DaImTo

+0

太糟糕了,這在https://developers.google.com/drive/v3/reference/files/get –

相關問題