谷歌云端硬盘API下载使用.NET错误
本文关键字:NET 错误 下载 云端 硬盘 API 谷歌 | 更新日期: 2023-09-27 18:30:22
我正在尝试使用C# .net从Google云端硬盘下载文件。我正在使用 https://developers.google.com/drive/web/manage-downloads 中的示例代码
代码无法编译并给出 IAuthenticator 的定义错误
error CS0234: The type or namespace name 'Authentication' does not exist in the namespace 'Google.Apis' (are you missing an assembly reference?)
error CS0246: The type or namespace name 'IAuthenticator' could not be found (are you missing a using directive or an assembly reference?)
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Services;
using Google.Apis.Authentication;
public static System.IO.Stream DownloadFile(
IAuthenticator authenticator, File file) {
我也试过
service.Files.Get(fileId).Download(myFileStream);
但是,这会在"进程已使用的文件"上给出错误
有没有人成功使用 C# 示例下载文件?
PS:我已经安装了所需的nuget pacakages。
PM> install-package Google.Apis.Auth
Attempting to resolve dependency 'Google.Apis.Core (≥ 1.9.0)'.
Attempting to resolve dependency 'Microsoft.Bcl (≥ 1.1.9)'.
Attempting to resolve dependency 'Microsoft.Bcl.Build (≥ 1.0.14)'.
Attempting to resolve dependency 'Microsoft.Bcl.Async (≥ 1.0.168)'.
Attempting to resolve dependency 'Microsoft.Net.Http (≥ 2.2.22)'.
Attempting to resolve dependency 'Newtonsoft.Json (≥ 6.0.4)'.
'Google.Apis.Auth 1.9.0' already installed.
GoogleDrive already has a reference to 'Google.Apis.Auth 1.9.0'.
用于
SDK的IAuthenticator身份验证器。谷歌 API 中没有太多关于 IAuthenticator 的详细信息,但您可以用于 API
fileID="asd383d8ied2edj82dnc0v";
Google.Apis.Drive.v2.Data.File file = service.Files.Get(fileId).Execute();
return service.HttpClient.GetStreamAsync(file.DownloadUrl).Result;