google drive api download使用.net错误

时间:2014-11-13 04:13:36

标签: c# google-drive-api

我正在尝试使用C#.net从谷歌驱动器下载文件。我使用的是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'.

1 个答案:

答案 0 :(得分:0)

用于SDK的IAuthenticator身份验证器。googleApi中关于IAuthenticator的详细信息并不多,但是您可以将其用于API

        fileID="asd383d8ied2edj82dnc0v";
        Google.Apis.Drive.v2.Data.File file = service.Files.Get(fileId).Execute();
        return  service.HttpClient.GetStreamAsync(file.DownloadUrl).Result;