1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
public List<Appointment> LoadAppointments(User user)
{
// key = chemin d'accès à mon fichier "P12"
// password = "notasecret"
// googleid = adresse mail qui se termine en "@developer.gserviceaccount.com"
// user.ExtertnalLogin = adresse mail du compte à consulter
X509Certificate2 certificate = new X509Certificate2(key, password, X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(googleid)
{
Scopes = new[] { CalendarService.Scope.Calendar },
User = admin,
}.FromCertificate(certificate));
service = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "<AppName>",
});
EventsResource.ListRequest req = service.Events.List(user.ExtertnalLogin);
req.ShowDeleted = true;
req.SingleEvents = true;
req.TimeZone = "UTC";
req.MaxResults = 1000;
req.UpdatedMin = LastSync;
req.TimeMin = DateTime.Today.AddMonths(-2);
Events events;
try
{
events = req.Execute();
}
catch (Exception e) // L'erreur se produit ici
{
Console.WriteLine(e.Message);
return null;
}
[...]
} |
Partager