Google Drive API V3:获取修订内容 [英] Google Drive API V3: get the content of a revision
问题描述
Google Drive API从V2更改为V3,请从响应中删除version.item.这些项目具有URL列表,它们是.txt,.pdf等文件(我使用的是直接HTTP协议,没有包装器).在V3中,似乎没有办法做到这一点.但是,有一个?alt = media参数,该参数应该返回文件,但是尝试它时出现403错误.
The Google Drive API change from V2 to V3, remove the revision.items from response. The items, had a list of urls, being the files in .txt, .pdf, etc. (I'm using straight HTTP protocol, no wrappers). In V3 there seems to be no way to do this. There is however an ?alt=media parameter, which is supposed to return a file, but I get a 403 error trying it.
有任何线索吗?
https://developers.google.com/drive/v3/reference/revisions/get
推荐答案
A.Google文件
对于Google Docs,由于无法使用Drive API v3检索修订文件,因此我使用新的变通办法对其进行了修改.新的解决方法是使用Drive API v2.Drive API v2的 drive.revisions.get
不仅可以检索修订列表,还可以检索导出链接.我想到了导出链接的用法.这成为当前情况的新解决方法.
A. Google Docs
For Google Docs, since the revision files would not be able to be retrieved using Drive API v3, I modified this using new workaround. The new workaround is to use Drive API v2. drive.revisions.get
of Drive API v2 can retrieve not only the revision list, but also the export links. I thought of the use of the export links. This became the new workaround for the current situation.
此示例使用修订版ID下载电子表格.
This sample downloads spreadsheet using revision ID.
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v2/files/### FileID ###/revisions?fields=items(exportLinks%2Cid)"
2.从导出链接中检索修订文件
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://docs.google.com/spreadsheets/export?id=### FileID ###&revision=### revision number ###&exportFormat=xlsx" \
-o outputfilename.xlsx
参考文献: https://developers.google.com/drive/v2/reference/revisions/get
对于除Google Docs以外的版本,修订ID只是文件ID.因此,您不仅可以使用修订版ID下载(模式1),还可以将其下载为普通文件(模式2).
In the case of except for Google Docs, the revision ID is just file ID. So you can download (Pattern 1) not only using revision ID, but also as a normal file (Pattern 2).
模式1:
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### FileID ###/revisions/### RevisionID ###?alt=media" \
-o outputfilename
模式2:
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### RevisionID ###?alt=media" \
-o outputfilename
参考文献: https://developers.google.com/drive/v3/reference/revisions/get
这篇关于Google Drive API V3:获取修订内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!