Google Calendar Integration using Windows Service

前提是你 提交于 2020-01-25 23:45:45

问题


I setup Google account and enabled Calendar API. I created OAuth2.0 authentication using installed application option and downloaded the client secret JSON file. I created a windows form application and manipulated the events in Google Calendar. First time it was asked access permission and it was granted, and the authentication token file created in %AppData% folder path. It was working fine.

But I need to create a windows service to add/update events in Google Calendar for different Google accounts. I am struggling here, how to get grant permission for any Google accounts programmatically?

Is there any other way to do without Google access permission? I searched for samples and didn't find anything related to windows service. Is there any examples available to manipulate Google calendar using Windows Service?

Update:

Using Service Account credential:

String serviceAccountEmail = 
              "xxxxxxxxxx-xxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com";

string path = AppDomain.CurrentDomain.BaseDirectory 
              + @"Configuration\" + "xxxxxxxxx-xxxxxxxx.p12";
var certificate = new X509Certificate2(path, "xxxxxxxxxx", X509KeyStorageFlags.Exportable);

ServiceAccountCredential credential = new ServiceAccountCredential
(
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
        {
            Scopes = new[] { CalendarService.Scope.Calendar }
        }.FromCertificate(certificate)
);

// Create the service.
calendarService = new CalendarService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "Test Calendar"
});

来源:https://stackoverflow.com/questions/30993669/google-calendar-integration-using-windows-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!