【问题标题】:Why am I getting a (401) Unauthorized Error in Google Calendar API为什么我在 Google Calendar API 中收到 (401) 未经授权的错误
【发布时间】:2010-10-03 09:10:01
【问题描述】:

我一直在使用 Google Calendar API,但遇到了一些问题。当我在下面调用它以删除日历事件时,它在第一次传递时工作正常,通常是第二次传递。但是,在我第二次或第三次调用此方法时,我得到一个 (401) 未经授权的错误。它每次都使用相同的凭据。如果我遇到异常,我可以在 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();
        }

【问题讨论】:

  • 如果您使用现有的 Feed URI 会发生什么?它是在网络浏览器中授权还是受到限制?

标签: c# google-calendar-api unauthorized


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

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

      在您的情况下,问题可能与刷新/访问令牌有关...我不确定。

      【讨论】:

        猜你喜欢
        • 2020-12-23
        • 2018-10-15
        • 2014-10-22
        • 1970-01-01
        • 2019-01-31
        • 2022-07-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多