Javascript 谷歌日历Api 401

Javascript 谷歌日历Api 401,javascript,google-api,google-calendar-api,Javascript,Google Api,Google Calendar Api,我有一个简单的代码,可以登录到谷歌,使用谷歌日历API,为用户创建日历和事件。代码运行良好,但我经常会从谷歌收到401登录所需的错误。如果我在浏览器中打开开发人员控制台并重试,它将正常工作。。。这很奇怪 var scopes = 'https://www.googleapis.com/auth/calendar'; var clientId = 'CLIENT_ID'; var apiKey = 'API_KEY'; function handleClientLoad() { gapi

我有一个简单的代码,可以登录到谷歌,使用谷歌日历API,为用户创建日历和事件。代码运行良好,但我经常会从谷歌收到401登录所需的错误。如果我在浏览器中打开开发人员控制台并重试,它将正常工作。。。这很奇怪

var scopes = 'https://www.googleapis.com/auth/calendar';
var clientId = 'CLIENT_ID';
var apiKey = 'API_KEY';

function handleClientLoad() {
    gapi.client.setApiKey(apiKey);
    window.setTimeout(checkAuth,1);
}

function checkAuth() {
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: true}, handleAuthResult);
}

function handleAuthResult(authResult) {
    var authorizeButton = $('#calendarAuth');
    var calendarFrame = $('#calendarFrame');
    if (authResult && !authResult.error) {
        authorizeButton.remove();
        calendarFrame.show();
        calendarFrame.attr('src', calendarFrame.attr('src')); //Hack to reload the iframe
    } else {
        authorizeButton.show();
        calendarFrame.hide();
    }
}

function Authorize() {
    gapi.auth.authorize({client_id: clientId, scope: scopes, immediate: false}, handleAuthResult);
    return false;
}


function GoogleScheduleFollowup(followup) {
    gapi.client.load('calendar', 'v3', function () {
        var request = gapi.client.calendar.events.insert({
            "calendarId": "primary",
            resource: {
                "summary": followup.title,
                "start": {
                    "dateTime": window.GetFullDateString(followup.date, followup.time)
                },
                "end": {
                    "dateTime": window.GetFullDateString(followup.date, followup.time)
                }
            }
        });

        request.execute(function (resp) {
            console.log(resp);
    });
}
在API控制台中,一切似乎都配置得很好,我敢肯定我们还没有达到配额(总数或每秒请求数)。例如,今天我提出了133个请求,其中36个因此错误而失败


我曾尝试每10分钟调用gapi.auth.authorize一次,以查看问题是否是会话超时,当我在另一个问题中阅读时,我尝试删除这一行
gapi.client.setApiKey(apiKey),都没有成功

这种情况多久发生一次?访问令牌是否已过期?客户端库应该根据需要刷新您的访问令牌,奇怪的是它没有这样做。我不认为调用authorize会有帮助,因为客户端lib应该知道它还没有过期,并且不需要刷新它。(我想)我有几个用户,所以很难确定它发生的频率。对一些人来说,这种情况似乎很快就会发生,而另一些人则可能在它开始发生前几个小时就发生了