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

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

问题描述

从Google Drive API v2到v3 迁移指南说:

The Google Drive API v2 to v3 migration guide says:

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

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

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

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.

我如何在v3中完成相同的任务?如果不可能,为什么要删除此有用的功能?

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

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

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?

在v3中没有办法获取文件的公共简短URL吗?

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

对于常规文件,显然是.

这似乎很好用(指向文件的公共短暂链接,并带有正确的名称和内容): https://www.googleapis.com/drive/v3/files/ID?alt=media&access_token=TOKEN

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

对于Google Apps文件,没有(甚至不是私有的,因为v2 exportLink以前是这样).

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

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

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

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

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.

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

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.

此文件命名问题使变通办法因v3中缺少ExportLinks而无效.

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

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

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.

使用诸如/drive/v3/files/FILEID/export之类的原始API调用(具有强制性access_token)构建链接将是一种足够接近的解决方法(它是临时的和公开的,无论如何都不是一样的).但是,命名问题使它无效.

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.

在v2中,常规文件的文件为WebContentLink,而Google Apps文件的文件为exportLinks.在v3中,exportLinks不见了,我看不到任何合适的替代方法.

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.

推荐答案

通过ID查询文件后,您可以使用getWebContentLink()函数获取文件的下载链接(例如$ file-> getWebContentLink( )).

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文档的下载网址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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