3

我一直在使用 Google Calendar API,但遇到了一些问题。当我在下面调用它来删除日历事件时,它在第一次传递时工作正常,通常是第二次传递。但是,在我第二次或第三次调用此方法时,我得到一个(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();
        }
4

3 回答 3

0

我认为需要更多信息。最好的方法是使用fiddler

于 2009-01-25T09:48:15.857 回答
0

您可以通过创建一个浏览器控件来解决此问题,该控件在加载时导航到 api 并且从不向用户显示它。唯一的解决方案是我发现 100% 解决了这个问题。

于 2012-04-05T19:17:31.623 回答
0

[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;
    }

也许在您的情况下,问题出在刷新/访问令牌上……我不确定。

于 2021-10-27T13:13:04.370 回答