Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Google.Apis.Auth.OAuth2;
- using System.Threading;
- using Google.Apis.Util.Store;
- using Google.Apis.Calendar.v3;
- using Google.Apis.Services;
- using System.IO;
- using System.Security.Cryptography.X509Certificates;
- namespace GoogleApiServer2ServerConsole
- {
- class Program
- {
- static void Main(string[] args)
- {
- // we have followed http://www.daimto.com/google-calendar-api-authentication-with-c/
- // you need to run PM> Install-Package Google.Apis.Calendar.v3
- // add the file abtained from Google Developers Console
- string keyFilePath = @"C:\Users\Ani\Documents\visual studio 2015\Projects\GoogleApiServer2ServerConsole\GoogleApiServer2ServerConsole\Server2Server-3de7c7534a5d.json";
- // check the file exists
- if (!File.Exists(keyFilePath))
- {
- Console.WriteLine("An Error occurred - Key file does not exist");
- return;
- }
- string[] scopes = new string[] {
- CalendarService.Scope.Calendar, // Manage your calendars
- CalendarService.Scope.CalendarReadonly // View your Calendars
- };
- var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
- ServiceAccountCredential credential = new ServiceAccountCredential(
- new ServiceAccountCredential.Initializer(serviceAccountEmail)
- {
- Scopes = scopes
- }.FromCertificate(certificate));
- }
- }
- }
Add Comment
Please, Sign In to add comment