尝试使用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'。存在显式转换(您是否缺少演员?)
答案 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;