0

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?)

Tim
  • 2,695
  • 3
  • 33
  • 39

1 Answers1

0

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;
eCorke
  • 858
  • 1
  • 10
  • 24