.net - Google API Service Account Initialisation -


i working on service should able insert calendar events user calendars various google apps domains using service account. works fine, came across small issue while initialising service using google api. initialisation described in google apis looks this:

        string[] scopes = new string[] { calendarservice.scope.calendar };         var certificate = new x509certificate2(service_account_pkcs12_file_path, "notasecret", x509keystorageflags.exportable);         try         {              serviceaccountcredential credential = new serviceaccountcredential(                 new serviceaccountcredential.initializer(service_account_email)                  {                     user = user,                     scopes = scopes                 }.fromcertificate(certificate));              calendarservice service = new calendarservice(new baseclientservice.initializer()             {                 httpclientinitializer = credential,             });             return service;         }          catch (exception ex)         {             return null;         } 

the problem having able check if calendarservice connected before try insert event. provided code snippet not run underlying network communication - initialise service. whole authentication process happens while executing events e.g.: var eventresult = neweventrequest.execute();

is there nice way how check if service connected before creating events (check httprequestexception, tokenresponseexception, etc.)? solution can think of insert simple event , delete right after or not use google api @ all.

thank in advance.

try refreshing token beforehand this:

if(credential.requestaccesstokenasync(cancellationtoken.none).result) {     authenticationkey = credential.token.accesstoken; } 

this try refresh access token providing way check service connectivity.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -