Я играю с API Календаря Google и зацикливаюсь на чем-то. Когда я называю это ниже удалить событие календаря , оно отлично работает на первом проходе и обычно на втором. Однако примерно во 2-й или 3-й раз, когда я вызываю этот метод, я получаю (401) несанкционированную ошибку . Он использует одни и те же учетные данные каждый раз. Если я получу исключение, я смогу сбросить учетные данные в перехвате, и все работает нормально. Я бы предпочел не делать этого. Есть идеи?
CalendarService myService = new CalendarService("mycompany-myapp-1");
myService.setUserCredentials("jo@username.com", "password");
// set the query for the event
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);
// find the event
EventFeed myResultsFeed = null;
try
{
// execute the query to find the event
myResultsFeed = myService.Query(myQuery);
}
catch (Exception ex)
{
// this is where i get the unauthorized exception
// if i reset the credentials here it works fine
myService.setUserCredentials("jo@username.com", "password");
myResultsFeed = myService.Query(myQuery);
}
if (myResultsFeed != null && myResultsFeed.Entries.Count > 0)
{
AtomEntry firstMatchEntry = myResultsFeed.Entries[0];
firstMatchEntry.Delete();
}