且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google Drive API V3:获取修订内容

更新时间:2023-02-14 12:11:55

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