I play with the Google Calendar API and get stuck on something. When I call it below deleting a calendar event , it works great on the first pass and usually the second. However, the second or third time I call this method, I get (401) Unauthorized error . It uses the same credentials every time. If I get an exception, I can reset the credentials in catch, and it works fine. I would rather not do this. Any ideas?
CalendarService myService = new CalendarService("mycompany-myapp-1");
myService.setUserCredentials("jo@username.com", "password");
EventQuery myQuery = new EventQuery(("http://www.google.com/calendar/feeds/jo@username.com/private/full"));
myQuery.Query = "Cut the grass";
myQuery.StartTime = DateTime.Now;
myQuery.EndTime = DateTime.Now.AddDays(1);
EventFeed myResultsFeed = null;
try
{
myResultsFeed = myService.Query(myQuery);
}
catch (Exception ex)
{
myService.setUserCredentials("jo@username.com", "password");
myResultsFeed = myService.Query(myQuery);
}
if (myResultsFeed != null && myResultsFeed.Entries.Count > 0)
{
AtomEntry firstMatchEntry = myResultsFeed.Entries[0];
firstMatchEntry.Delete();
}
source
share