Google C#Api Beta 1.6身份验证问题 [英] Google C# Api Beta 1.6 Authentication Issue

查看:95
本文介绍了Google C#Api Beta 1.6身份验证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用C#Beta v1.6 SDK
进行身份验证和访问Google Calendar Service,并且看起来不正确

 使用系统; 
使用System.Collections.Generic;
使用System.Linq;
使用System.Text;
使用System.Threading.Tasks;

使用Google.Apis.Auth.OAuth2;
使用Google.Apis.Auth;
使用Google.Apis.Authentication;
使用Google.Apis.Calendar.v3;
使用System.Threading;
使用Google.Apis;
使用Google.Apis.Services;


$ b 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示例:任务VB示例



我得到的错误消息是:



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

解决方案 AuthorizeAsync 是异步的,所以它返回任务< T> 不是确切的结果。在你的情况下,你需要得到返回任务< T> 的属性结果

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


Trying to Authenticate and access Google Calendar Service with C# Beta v1.6 SDK and something does not look right

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"
        });

In particular this line: HttpClientInitializer = uc,

I'm following Task vb example: Tasks VB Sample

The error message that I get is this:

Error 1 Cannot implicitly convert type 'System.Threading.Tasks.Task' to 'Google.Apis.Http.IConfigurableHttpClientInitializer'. An explicit conversion exists (are you missing a cast?)

解决方案

function AuthorizeAsync is async, so it returns Task<T> not exact result. In your case you need to get property Result of return Task<T>.

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

这篇关于Google C#Api Beta 1.6身份验证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆