【问题标题】:BaseClientService does not contain a definition of FilesBaseClientService 不包含 Files 的定义
【发布时间】:2016-05-20 12:59:26
【问题描述】:

我在使用来自 google Nuget 包 (Google.Apis.Drive.v3) 的 DriveService 时遇到问题。

我收到此错误:

严重性代码描述项目文件行抑制状态 错误 CS1061“BaseClientService”不包含“Files”的定义,并且找不到接受“BaseClientService”类型的第一个参数的扩展方法“Files”(您是否缺少 using 指令或程序集引用?) Sampleproject.Web C :\sample\Sampleproject.Web\Controllers\DriveController.cs 117 活动

我正在使用官方文档中的部分指南:https://developers.google.com/drive/v3/web/quickstart/dotnet#step_1_turn_on_the_api_name

最初我认为这只是我缺少的“使用”,但我似乎无法弄清楚/谷歌我的方式。

编辑:

我的服务如下所示:

我的用户凭据如下所示:

【问题讨论】:

    标签: c# asp.net-web-api google-api google-drive-api google-api-dotnet-client


    【解决方案1】:

    我不确定您是如何创建 service 的,但您可以尝试:

    我猜你正在做这样的事情。

    // Create Drive API service.
    var service  = new BaseClientService.Initializer()
        {
        HttpClientInitializer = credential,
        ApplicationName = "Drive Authentication Sample",
        };
    

    在这种情况下,您应该像这样声明服务。

    // Create Drive API service.
    var service  = new DriveService(new BaseClientService.Initializer()
        {
         HttpClientInitializer = credential,
         ApplicationName = "Drive Authentication Sample",
         });
    

    更新:

    部分问题可能是您正在混合使用 V2 和 V3。

    using Google.Apis.Drive.v3;
    

    列表:

    var pageStreamer = new PageStreamer<Google.Apis.Drive.v3.Data.File, FilesResource.ListRequest, Google.Apis.Drive.v3.Data.FileList, string>(
                                                       (request, token) => request.PageToken = token,
                                                       response => response.NextPageToken,
                                                       response => response.Files);
    
    var req = service.Files.List();
    req.PageSize = 1000;
    
    
    foreach (var result in pageStreamer.Fetch(req))
         {
         Console.WriteLine(result.Id);
         } 
    

    【讨论】:

    • 检查更新可能要选择一个 api 版本而不是同时使用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多