【问题标题】:Google Calendar API returning 403 for some usersGoogle Calendar API 为某些用户返回 403
【发布时间】:2021-06-30 17:46:22
【问题描述】:

我集成了一个小功能,可以从我组织的谷歌日历的每个成员中读取日历事件。它适用于大多数人,但有几个会返回 403。

我认为这是因为他们可能有多个谷歌帐户连接到日历,而我无权阅读其他帐户。这是我能想到的唯一原因。希望有人可以在这里提供帮助 - 真的被困在修复中。

我没有使用“只读”范围。下面是为用户加载日历事件的 react 函数。

    const loadCalendar = () => {
    window.gapi.load('client:auth2', () => {
        console.log("fetching calendar for: ", userEmail);

        gapi.client.init({
            apiKey: "xyz",
            clientId: "xyz",
            discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"],
            scope: "https://www.googleapis.com/auth/calendar",
        })

        gapi.client.load('calendar', 'v3', () => {
            gapi.auth2.getAuthInstance().then(() => {
                gapi.client.calendar.events.list({
                    'calendarId': 'primary',
                    'timeMin': (new Date()).toISOString(),
                    'showDeleted': false,
                    'singleEvents': true,
                    'maxResults': 12,
                    'orderBy': 'startTime',
                }).then(({ result }) => {
                    let filteredArr = [];
                    result.items.forEach(item => {
                        let obj = {
                            key: item.id,
                            attendees: item.attendees,
                            start: item.start["date"] ? item.start["date"] : new Date(item.start["dateTime"]).toLocaleString(),
                            summary: item.summary,
                            zoomLink: item.location
                        }
                        filteredArr.push(obj);
                    })
                    setCalendarEvents(filteredArr)
                })
            })
        })
    });
}

【问题讨论】:

  • 你好@Tony!为了更好地分析您的情况,请分享有问题的代码。随意隐藏任何私人信息。另外请说明您是否使用域范围的委派。
  • @Jacques-GuzelHeron 非常感谢您的关注。真的把我难住了。在编辑中添加了删除秘密的代码。

标签: reactjs google-calendar-api google-api-js-client


【解决方案1】:

查看脚本后,我了解到该脚本适用于您组织中的每个用户,但两个特定用户除外。在这种情况下,我强烈建议您创建一个Workspace domain-wide delegation of authority。通过该操作,您将创建一个额外的帐户,该帐户可以访问组织中的每个用户数据,因此您可以访问这两个用户的日历。唯一需要的更新是在您的脚本中使用新的帐户凭据。请检查链接的示例,如果它在您的场景中不起作用,请回信。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-19
    • 2014-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多