Google C#Api Beta 1.6身份验证问题



尝试使用C#Beta v1.6 SDK验证和访问Google日历服务有些东西看起来不对劲

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

下面是任务vb示例:任务vb示例

我得到的错误信息是:

错误1无法将类型"System.Threading.Tasks.Task"隐式转换为"Google.Apis.Http.IConfigurableHttpClientInitializer"。存在显式转换(是否缺少强制转换?)

函数AuthorizeAsync是异步的,所以它返回的Task<T>不是精确的结果。在您的情况下,您需要获得返回Task<T>的属性Result

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

相关内容

  • 没有找到相关文章

最新更新