I am able to retrieve event from google calendar API using OAuth authentication by code given here, but how to code for getting event information using API key.
Asked
Active
Viewed 3,628 times
-2
-
Have you had a look at the API documentation? There is a specific entry for Events https://developers.google.com/google-apps/calendar/v3/reference/ – Stevie Feb 05 '16 at 09:34
-
Yes gone through this pages but not found any code for C#.net. – Pritesh Chhunchha Feb 05 '16 at 09:37
-
only https://developers.google.com/google-apps/calendar/quickstart/dotnet I found – Pritesh Chhunchha Feb 05 '16 at 09:38
-
I am asking for API key!!! – Pritesh Chhunchha Feb 05 '16 at 09:39
-
A quick google found this: https://support.google.com/cloud/answer/6158862?hl=en&ref_topic=6262490 – Stevie Feb 05 '16 at 09:53
-
I have done this step but I want code to apply in c# language to get information from google calendar API. – Pritesh Chhunchha Feb 05 '16 at 10:09
1 Answers
1
API key is for use with PUBLIC data. For an API key to work with a calendar I would assume said calendar would have to be set to public.
var service = new CalendarService(new BaseClientService.Initializer()
{
ApiKey = "XXX",
ApplicationName = "xyz",
});
var events = service.Events.List("en.danish#holiday@group.v.calendar.google.com").Execute();
foreach (var myEvent in events.Items)
{
Console.WriteLine(string.Format("Event: {0} Start: {1} End: {2}", myEvent.Summary, myEvent.Start.DateTime.ToString(), myEvent.End.DateTime.ToString()));
}
I have an example / tutorial of accessing events on public calendars here
I think you should consider looking at a service account instead this will allow you to grant the service account access to your calendar and you wont need to go though the Oauth2 authentication which I suspect is what you don't want to be doing.
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));
I have a tutorial on how to us a service account here

Linda Lawton - DaImTo
- 106,405
- 32
- 180
- 449
-
I have used service account with API version 3.0 when I try to get calendar by CalendarList calendars = request1.Execute(); it gives calendar count as 0. But id I shared service account email Id to my gmail account(xxxx@gmail.com) then I am getting the events information properly. – Pritesh Chhunchha Feb 16 '16 at 06:32