C# 为什么我在谷歌日历API中遇到(401)未经授权的错误
我一直在玩弄谷歌日历API,我被一些东西卡住了。当我在下面调用它来删除日历事件时它在第一次通过时工作正常,通常在第二次通过时工作正常。然而,大约在我调用此方法的第二次或第三次时,我得到一个(401)未经授权的错误。它每次都使用相同的凭据。如果我得到异常,我可以重置catch中的凭据,它工作正常。我宁愿不这样做。有什么想法吗C# 为什么我在谷歌日历API中遇到(401)未经授权的错误,c#,google-calendar-api,unauthorized,C#,Google Calendar Api,Unauthorized,我一直在玩弄谷歌日历API,我被一些东西卡住了。当我在下面调用它来删除日历事件时它在第一次通过时工作正常,通常在第二次通过时工作正常。然而,大约在我调用此方法的第二次或第三次时,我得到一个(401)未经授权的错误。它每次都使用相同的凭据。如果我得到异常,我可以重置catch中的凭据,它工作正常。我宁愿不这样做。有什么想法吗 CalendarService myService = new CalendarService("mycompany-myapp-1"); m
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%解决了这个问题。如果使用您拥有的提要URI,会发生什么?它是在webbrowser中授权的还是受限的?