简体   繁体   English

Google Drive直接(原始)链接下载图像文件

[英]Google drive direct(raw) link to download image file

I need to feed image into printing company. 我需要将图像送入印刷公司。 For that I need direct image link. 为此,我需要直接的图像链接。 Is it possible to get the link that, if used by curl immediately return content of the file. 是否有可能获得链接,如果由curl使用,则立即返回文件内容。

For example, I have shared file https://drive.google.com/drive/u/0/folders/0B_dyDrMQHCjHMjF6LVpTRGRwSFk is it possible to get a link which would, when used with 例如,我共享了文件https://drive.google.com/drive/u/0/folders/0B_dyDrMQHCjHMjF6LVpTRGRwSFk ,可以获取一个链接,当与

curl <something>?id=0B_dyDrMQHCjHMjF6LVpTRGRwSFk

which, when run, will produce 运行时会产生

/*
Firebase Authentication Working Example, JavaScript, CSS, and HTML 
crafted with love and lots of coffee.
*/
html body {

etc. I have an image file, this ccs file is just an example, but I can't find a way to get it work. 等。我有一个图像文件,此ccs文件只是一个示例,但我找不到使它工作的方法。 There are webcontent and webview link properties for file, but neither of them seem to do the trick. 有文件的webcontent和webview链接属性,但似乎都不起作用。

Anyone know the solution/workaround for this? 有人知道解决方案/解决方法吗?

Since you are using the php, you can use Download Files for REST API: 由于您使用的是php,因此可以使用REST API的下载文件

The Drive API allows you to download files that are stored in Google Drive. 云端硬盘API允许您下载存储在Google云端硬盘中的文件。 Also, you can download exported versions of Google Documents (Documents, Spreadsheets, Presentations, etc.) in formats that your app can handle. 另外,您可以下载应用可以处理的格式的Google文档的导出版本(文档,电子表格,演示文稿等)。 Drive also supports providing users direct access to a file via the URL in the webViewLink property. 云端硬盘还支持通过webViewLink属性中的URL为用户提供直接访问文件的webViewLink

Depending on the type of download you'd like to perform — a file, a Google Document, or a content link — you'll use one of the following URLs: 根据您要执行的下载类型(文件,Google文档或内容链接),您将使用以下网址之一:

GET https://www.googleapis.com/drive/v3/files/0B9jNhSvVjoIVM3dKcGRKRmVIOVU?alt=media
Authorization: Bearer <ACCESS_TOKEN>

To download files, you make an authorized HTTP GET request to the file's resource URL and include the query parameter alt=media 要下载文件,请向文件的资源URL发出授权的HTTP GET请求,并包含查询参数alt=media

Here is a sample code for PHP: 这是PHP的示例代码:

$fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
$response = $driveService->files->get($fileId, array(
    'alt' => 'media'));
$content = $response->getBody()->getContents();

Hope this helps. 希望这可以帮助。

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

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