【发布时间】:2010-10-03 09:10:01
【问题描述】:
我一直在使用 Google Calendar API,但遇到了一些问题。当我在下面调用它以删除日历事件时,它在第一次传递时工作正常,通常是第二次传递。但是,在我第二次或第三次调用此方法时,我得到一个 (401) 未经授权的错误。它每次都使用相同的凭据。如果我遇到异常,我可以在 catch 中重置凭据,它可以正常工作。我宁愿不必这样做。有什么想法吗?
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();
}
【问题讨论】:
-
如果您使用现有的 Feed URI 会发生什么?它是在网络浏览器中授权还是受到限制?
标签: c# google-calendar-api unauthorized