2

I am developing calendar api client and I have problem with reminder - they do not work...

I create event like this:

Event gEvent = new Event()
{
Summary = "Reminder test",
Location = "Reminder test",
Start = new EventDateTime()
{
DateTime = new DateTime(2014, 12, 14, 21, 0, 0),
},
End = new EventDateTime()
{
DateTime = new DateTime(2014, 12, 14, 22, 0, 0),
},
Reminders = new Event.RemindersData()
{
UseDefault = false,
Overrides = new List<EventReminder>() 
{
new EventReminder()
{
Method = "email",
Minutes = 15
},
new EventReminder()
{
Method = "email",
Minutes = 30
},
new EventReminder()
{
Method = "email",
Minutes = 45
},
}
}
};
Event simpleEvent = calService.Events.Insert(gEvent, strCalendarID).Execute();

This code works and in my google calendar GUI is really created my event, but if I click on editing event - I can not see my reminders, there are only default reminders. Why? What I am doing wrong?

Thanks for all answers


Today I attempted send request from code with JSON. My method look like this:

private static void CreateSimpleEvent(string strAccessToken, string strCalendarID, string strApiKey)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(string.Format("https://www.googleapis.com/calendar/v3/calendars/{0}/events?sendNotifications=false&fields=reminders&key={1}", strCalendarID, strApiKey));
        request.Method = "POST";
        request.ContentType = "application/json";
        request.UserAgent = "TestCalendarApi2";
        request.Headers.Add("Authorization", "Bearer " + strAccessToken);

        string strJson = @"{
                        'end': {
                        'dateTime': '2014-12-19T15:30:00.000Z',
                        'timeZone': 'Europe/Prague'
                        },
                        'start': {
                        'dateTime': '2014-12-19T14:30:00.000Z',
                        'timeZone': 'Europe/Prague'
                        },
                        'reminders': {
                        'useDefault': false,
                        'overrides': [
                        {
                        'method': 'email',
                        'minutes': 13
                        }
                        ]
                        }
                        }";

        using (var streamWriter = new StreamWriter(request.GetRequestStream()))
        {
            streamWriter.Write(strJson);
            streamWriter.Flush();
            streamWriter.Close();

            var httpResponse = (HttpWebResponse)request.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
            }
        }
    }

Method proceeded OK and in google calendar was created event, but reminders are still missing when I use AccessToken from ServiceAccountCredential object :(. When I use AccessToken generated in Apis explorer (https://developers.google.com/apis-explorer/#p/calendar/v3/) - reminders are working. Problem is, that in Apis explorer I must turn on OAuth2 and after that I must grand acess...

Is there any way, how to grand access from code?

Thanks for all answers.

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Martin Zaloga
  • 127
  • 1
  • 10

2 Answers2

1

The problem with reminders while using a service account to manage events in Google Calendar is that the service account is practically a virtual user with its own Google Calendar. The event reminders are set per user, so you would be only able to see the reminders if you'd manage to log in to Google Calendar as your service account. The users who share the calendar with the service account only see the event details but they have to set their own reminders.

Kizivat
  • 183
  • 3
  • 14
0

Same issue here, event inserted without any reminders. Sending same request via API explorer successfully inserted event with reminders.

My JSON data:

{  
   "end":{  
      "dateTime":"2015-01-19T01:20:00.000",
      "timeZone":"Europe\/Minsk"
   },
   "reminders":{  
      "useDefault":false,
      "overrides":[  
         {  
            "method":"sms",
            "minutes":"30"
         },
         {  
            "method":"email",
            "minutes":"60"
         }
      ]
   },
   "start":{  
      "dateTime":"2015-01-19T01:15:00.000",
      "timeZone":"Europe\/Minsk"
   },
   "summary":"New event",
   "start_date":"2015-01-19 01:15",
   "end_date":"2015-01-19 01:20"
}
zergussino
  • 821
  • 11
  • 14