问题
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