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

时间:2013-12-03 03:51:04

标签: c# google-api google-calendar-api

尝试使用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示例:Tasks VB Sample

我得到的错误信息是:

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

1 个答案:

答案 0 :(得分:0)

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

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