using System;
using System.IO;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Text;
using System.Diagnostics;
//For use in class CalandarMainV3 : An entirely new class needed to
using System.Threading;
using System.Threading.Tasks;
using Google;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;
namespace RepBusGoogleCalendarV3
{
public class CalandarMainV3
{
const String ClientSecretsFile = "C:\\Users\\user1\\Documents\\Visual Studio 2010\\Projects\\Programming\\Projects\\Google Ops\\client_secrets.json";
bool m_Init;
public CalandarMainV3()
{
Console.WriteLine("Calling: AuthGoogleDataInterface()");
m_Init = AuthGoogleDataInterface();
}
private bool AuthGoogleDataInterface()
{
bool b_success;
try
{
Console.WriteLine("New User Credential");
// New User Credential
UserCredential credential;
using (var stream = new FileStream(ClientSecretsFile, FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { CalendarService.Scope.Calendar },
"user", CancellationToken.None,
null).Result;
//new FileDataStore("My.cal")).Result;
}
Console.WriteLine("New Service");
// Create the service.
var service = new CalendarService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "My Calendar API",
});
Console.WriteLine("AuthGoogleDataInterface: Success");
b_success = true;
}
catch (Exception e)
{
string cs_err;
cs_err = e.Message;
Console.WriteLine(cs_err);
Console.WriteLine(e.Source);
Console.WriteLine("AuthGoogleDataInterface: Fail");
b_success = false;
throw;
}
return b_success;
}
}
}