私は Google カレンダー API をいじっていて、何かに行き詰まっています。以下でこれを呼び出してカレンダーイベントを削除すると、最初のパスと通常は2番目のパスで正常に機能します。ただし、このメソッドを 2 回目または 3 回目に呼び出すと、(401) Unauthorized error が発生します。毎回同じ資格情報を使用します。例外が発生した場合は、キャッチで資格情報をリセットでき、正常に動作します。私はこれをする必要がないことを望みます。何か案は?
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();
}