为什么我在Google Calendar API中收到(401)未经授权的错误

我一直在使用谷歌日历API,并陷入困境。 当我在下面调用它来删除日历事件时,它在第一遍和第二阶段正常工作。 但是,在第二次或第三次我称这种方法时,我得到(401)未经授权的错误 。 它每次都使用相同的凭据。 如果我得到exception,我可以重置 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(); } 

我认为需要更多信息。 最好的方法是使用小提琴手 。

你可以通过创建一个webbrowser控件来解决这个问题,该控件在加载时导航到api并且永远不会向用户显示它。 只有解决方案我发现100%解决了这个问题。