简体   繁体   English

从Google Drive API v3下载Gdoc修订版

[英]Downloading Gdoc revisions from Google Drive API v3

You can't I know. 你不知道 From the docs , 文档中

Once you get a list of a file's revisions, you can download the content of any revision by calling the revisions.get method with the parameter alt=media. 一旦获得文件修订的列表,就可以通过使用参数alt = media调用versions.get方法来下载任何修订的内容。 Revisions for Google Docs, Sheets, and Slides can not be downloaded. 无法下载Google文档,表格和幻灯片的修订。

But I'd like to download(pdf) different versions of the same Gdoc file based on date. 但我想根据日期下载(pdf)同一Gdoc文件的不同版本。 From the Drive web app you can view versions and print them or restore a version to the head. 在云端硬盘网络应用中,您可以查看版本并进行打印或将版本恢复到头部。 Is there any way to achieve either using the API? 有什么方法可以使用API​​来实现? Can you restore some version ? 您可以还原一些版本吗? Then you could export the file. 然后,您可以导出文件。

I searched the internets, but couldn't find a way around this. 我搜索了互联网,但找不到解决方法。

I'm using the java client api, which gives me this when I try to make a media get request. 我正在使用Java客户端api,当我尝试发出媒体获取请求时,它会向我提供此信息。

{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "location" : "alt",
    "locationType" : "parameter",
    "message" : "Only files with binary content can be downloaded. Use Export with Google Docs files.",
    "reason" : "fileNotDownloadable"
  } ],
  "message" : "Only files with binary content can be downloaded. Use Export with Google Docs files."
}

But I can figure it out if you can answer for any other API too. 但是我可以弄清楚您是否也可以回答任何其他API。

Looks like a v3 specific issue. 看起来像是v3的特定问题。 I suggest using v2 for that particular call. 我建议对该特定呼叫使用v2。 See https://developers.google.com/drive/v2/reference/revisions#resource , where you will see that the revision resource contains an array called exportLinks. 请参阅https://developers.google.com/drive/v2/reference/revisions#resource ,在这里您将看到修订资源包含一个名为exportLinks的数组。 Within that you should find an element {"pdf":" https://xxxxxxxx "}. 在其中,您应该找到一个元素{“ pdf”:“ https:// xxxxxxxx ”}。 Make an authenticated GET on that URL. 在该URL上进行身份验证的GET。

imho, the provided libraries cause as many problems as they solve. 恕我直言,所提供的库导致了许多解决的问题。 This is a case in point where the library masks access to the v2 API, even though the v2 API is fully supported. 在这种情况下,即使完全支持​​v2 API,库也会屏蔽对v2 API的访问。 So in your code, you will need to extract the Access Token from the drive service object, set that as an http Authorization: Bearer 4a343234we43w43w44 header, then make the two GET REST calls to GET the revisions list and then GET the url corresponding to pdf in the exportLinks. 因此,在您的代码中,您将需要从驱动器服务对象中提取访问令牌,并将其设置为http Authorization: Bearer 4a343234we43w43w44标头,然后进行两个GET REST调用以获取修订列表,然后获取与pdf对应的url。在exportLinks中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM