Google C#Api Beta 1.6身份validation问题

尝试使用C#Beta v1.6 SDK对Google日历服务进行身份validation和访问时看起来不对

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Google.Apis.Auth.OAuth2; using Google.Apis.Auth; using Google.Apis.Authentication; using Google.Apis.Calendar.v3; using System.Threading; using Google.Apis; using Google.Apis.Services; var uc = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets() { ClientId = string.Empty, ClientSecret = string.Empty }, new[] { CalendarService.Scope.Calendar }, "user", CancellationToken.None); var service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = uc, ApplicationName = "Google Calendar Test" }); 

特别是这一行: HttpClientInitializer = uc

我正在关注Task vb示例: Tasks VB Sample

我得到的错误信息是这样的:

错误1无法将类型’System.Threading.Tasks.Task’隐式转换为’Google.Apis.Http.IConfigurableHttpClientInitializer’。 存在显式转换(您是否错过了演员?)

函数AuthorizeAsync是异步的,因此返回Task不是精确的结果。 在您的情况下,您需要获得属性返回Task

 var uc = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets() { ClientId = string.Empty, ClientSecret = string.Empty }, new[] { CalendarService.Scope.Calendar }, "user", CancellationToken.None).Result;