[英]Why am I getting a (401) Unauthorized Error in Google Calendar API
我一直在玩谷歌日历 API,但遇到了一些问题。 当我在下面调用它以删除日历事件时,它在第一遍和通常第二遍工作正常。 但是,大约在第 2 次或第 3 次调用此方法时,我收到(401) Unauthorized error 。 它每次都使用相同的凭据。 如果我得到异常,我可以在 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%解决了这个问题。
我认为需要更多信息。 最好的方法是使用小提琴手 。
[NODE JS]我知道那是 8 年前,但不知何故我遇到了这样的错误并从堆栈中得到了这个 :) 我忘记将“auth”对象传递给请求。 完整的架构是:
interface Params$Resource$Events$Delete extends StandardParameters {
/**
* Auth client or API Key for the request
*/
auth?: string | OAuth2Client | JWT | Compute | UserRefreshClient;
/**
* Calendar identifier. To retrieve calendar IDs call the calendarList.list
* method. If you want to access the primary calendar of the currently
* logged in user, use the "primary" keyword.
*/
calendarId?: string;
/**
* Event identifier.
*/
eventId?: string;
/**
* Deprecated. Please use sendUpdates instead. Whether to send
* notifications about the deletion of the event. Note that some emails
* might still be sent even if you set the value to false. The default is
* false.
*/
sendNotifications?: boolean;
/**
* Guests who should receive notifications about the deletion of the event.
*/
sendUpdates?: string;
}
也许在您的情况下,问题可能与刷新/访问令牌有关...我不确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.