Google Drive API v3:没有任何方法可以获取 Google 文档的下载 url? [英] Google Drive API v3 : there isn't any way to get a download url for a google document?

查看:14
本文介绍了Google Drive API v3:没有任何方法可以获取 Google 文档的下载 url?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Drive API v2 到 v3 迁移指南 说:><块引用>

exportLinks 字段已从文件中删除.要导出 Google 文档,请改用 files.export 方法.

我不想立即导出(下载)文件.files.export"实际上会下载文件.我想要一个链接来下载文件,稍后.这在 v2 中可以通过 exportLinks 实现.

我如何在 v3 中实现相同的功能?如果不可能,为什么删除了这个有用的功能?

此外,(与上述问题类似)downloadUrl 也被删除,建议的替代方案(files.get with ?alt=media")下载文件而不是提供下载链接.这意味着在 v3 中无法获得文件的公共短期 URL?

<块引用>

在 v3 中没有办法获得文件的公共短期 URL?

对于普通文件,显然是的.

这似乎工作正常(具有正确名称和内容的文件的公共短期链接):https://www.googleapis.com/drive/v3/files/ID?alt=media&access_token=TOKEN

对于谷歌应用程序文件,没有(甚至不是私有的,就像 v2 exportLinks 过去那样).

https://www.googleapis.com/drive/v3/files/ID/exportmimeType=TYPEv&access_token=TOKEN

与常规文件类似,此 URL 是指向文件内容的短暂链接,但缺少正确的名称.

顺便说一句,我看到 API 的行为不一致:/drive/v3/files/FILEID 提供正确的文件名,但 /drive/v3/files/FILEID/export 没有.

我认为 API 本身应该设置正确的 Content-Disposition,正如它在发出 /drive/v3/files/FILEID 调用时显然所做的那样.

此文件命名问题使 v3 中缺少导出链接的解决方法无效.

v2 ExportLinks 允许我链接文件(这与立即获取其内容不同).任何登录并拥有适当权限的人都可以访问它,并且该链接不需要任何 access_token,而且它不是短暂的.它很好而且很有用.

使用像 /drive/v3/files/FILEID/export 这样的原始 API 调用(带有强制访问令牌)构建链接将是一个足够接近的解决方法(它是临时的和公共的,不一样反正就是这样).然而,命名问题使其无效.

在 v2 中,常规文件有一个 WebContentLink,谷歌应用文件有 exportLinks.在 v3 中 exportLinks 不见了,我看不到任何合适的替代品.

解决方案

一旦你通过 id 查询你的文件,你就可以使用函数 getWebContentLink() 来获取文件的下载链接(例如 $file->getWebContentLink() ).

The Google Drive API v2 to v3 migration guide says:

The exportLinks field has been removed from files. To export Google Documents, use the files.export method instead.

I don't want to export (download) the file right away. "files.export" will actually download the file. I want a link to download the file, later. This was possible in v2 by means of the exportLinks.

How can I in v3 accomplish the same? If it is not possible, why was this useful feature removed?

Besides, (similar problem to above) downloadUrl was also removed, and the suggested alternative ("files.get with ?alt=media") downloads the file instead of providing a download link. This means there is no way in v3 to get a public short lived URL for a file?

EDIT:

there is no way in v3 to get a public short lived URL for a file?

For regular files, apparently yes.

This seems to work fine (a public short lived link to the file with its right name and contents): https://www.googleapis.com/drive/v3/files/ID?alt=media&access_token=TOKEN

For google apps files, no (not even private, as v2 exportLinks used to be).

https://www.googleapis.com/drive/v3/files/ID/exportmimeType=TYPEv&access_token=TOKEN

Similar to regular files, this URL is a short lived link to the file contents, but lacking of its right name.

BTW, I see the API is not behaving consistently: /drive/v3/files/FILEID delivers the right file name, but /drive/v3/files/FILEID/export does not.

I think the API itself should be setting the right Content-Disposition, as it is apparently doing when issuing a /drive/v3/files/FILEID call.

This file naming problem invalidates the workaround to the lack of ExportLinks in v3.

The v2 ExportLinks allowed me to link a file (which is not the same as getting its content right away). Anyone logged in and with the proper permissions was able to access it, and the link didn't needed any access_token, and it wasn't short lived. It was good and useful.

Building a link with a raw API call like /drive/v3/files/FILEID/export (with mandatory access_token) would be an close enough workaround (it is temporary and public, not the same as it was, anyway). However, the naming problem invalidates it.

In v2, regular files have a WebContentLink and google apps files have exportLinks. In v3 exportLinks are gone, and I don't see any suitable alternative to them.

解决方案

Once you query for your file by id you can use the function getWebContentLink() to get the download link of the file (eg. $file->getWebContentLink() ).

这篇关于Google Drive API v3:没有任何方法可以获取 Google 文档的下载 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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