通过 WebClient C# 从 Google.Drive 下载文件

Download the file from Google.Drive via WebClient C#

我需要在以下位置下载文件:https://drive.google.com/u/0/uc?id=1sSR9kWifwjIP5qFWcyxGCxN0-MoEd_oo&export=download

但是下载文件后,我得到的文件只有一行:“Google Drive-Virus 扫描警告”。理论上,我应该从url中指定的link下载文件(我是通过浏览器控制台获取的),但我下载了一个看不懂的文件,一行。据我所知,我下载了页面标记,但没有下载文件本身。如何解决这个问题?

要下载文件,请使用以下方法:

using System;
using System.Net;


public class Program
{

    public static void Main(string[] args)
    {
        {
            string url = "https://drive.google.com/u/0/uc?export=download&confirm=pKfr&id=1sSR9kWifwjIP5qFWcyxGCxN0-MoEd_oo";
            string savePath = @"C:\Users\Saint\Desktop\TaskRetail\yml.xml";
            WebClient client = new WebClient();
            client.DownloadFile(url, savePath);
            Console.ReadLine();
        }
    }

参考:https://bytesbin.com/skip-google-drive-virus-scan-warning-large-files/

创建凭据:

将生成一个 API 密钥,复制密钥并将其粘贴到我们稍后需要的地方。

第 2 步。调整共享 URL

在没有任何病毒警告的情况下直接寻找您希望下载的 Google 驱动器文件。 在这里复制文件 ID 并将其粘贴到安全的地方

打开Chrome并输入以下内容Google APIs URL.

https://www.googleapis.com/drive/v3/files/FileID?alt=media&key=APIKey

在文件 ID 部分输入复制的文件 ID,在 API 密钥部分输入 API 密钥。

按 Enter 键,文件将开始下载,没有任何警告符号。