简体   繁体   English

使用c#从谷歌驱动器下载文件而不使用谷歌API

[英]Download file from google drive using c# without google API

As per the requirement ,the client is provide with an exe-(which contains the url of file to be downloaded) If we use the google api, we need to provide additional references along with the exe. 根据要求,客户端提供exe-(包含要下载的文件的URL)如果我们使用google api,我们需要提供额外的引用以及exe。 It is not allowed by the client. 客户不允许这样做。

I used the webclient to download the file, but its downloading the file with doc type as HTML. 我使用webclient下载文件,但是它下载文件类型为HTML的文件。 My requirement is to download the file form google drive without using google API . 我的要求是在不使用谷歌API的情况下从谷歌驱动器下载文件。 Is there any way to do that? 有没有办法做到这一点?

I have tried the code as below 我已经尝试了如下代码

 WebClient wb = new WebClient();          
 wb.DownloadFile("https://drive.google.com/file/d/0BzpAdEg-KyDjNVVSb0FBOWQ4V0k/view?usp=sharing", @"C:\TFS\test\test.pdf");

Result as shown below 结果如下图所示

在此输入图像描述

This should help you. 这应该对你有帮助。

Below is the standard sharing url for google drive. 以下是谷歌硬盘的标准共享网址。

https://drive.google.com/file/d/FILE_ID/edit?usp=sharing

the format you need to use for direct downloads is: 您需要用于直接下载的格式是:

https://drive.google.com/uc?export=download&id=FILE_ID

this will link directly to the file instead of to the drive view in your current example. 这将直接链接到文件而不是当前示例中的驱动器视图。

so, for example, if your sharing url is https://drive.google.com/file/d/ABCDEFG1234567/edit?usp=sharing 因此,例如,如果您的共享网址是https://drive.google.com/file/d/ABCDEFG1234567/edit?usp=sharing

then your direct download url is https://drive.google.com/uc?export=download&id=ABCDEFG1234567 那么您的直接下载网址是https://drive.google.com/uc?export=download&id=ABCDEFG1234567

Note, this is only for files you have uploaded yourself that were not created in drive itself (ie, doc, presentation, spreadsheet) using the google docs. 请注意,这仅适用于您自己上传的文件,这些文件不是使用Google文档在驱动器本身(即文档,演示文稿,电子表格)中创建的。 to do that the format changes (will update answer if you need it) 为此,格式更改(如果需要,将更新答案)

Edit: 编辑:

It is worth noting that if the files location changes then the url and direct download link will change too, meaning you will need to update it. 值得注意的是,如果文件位置发生变化,那么网址和直接下载链接也会发生变化,这意味着您需要更新它。

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

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