Node.js nodejs googleapis calendar.events关键问题

Node.js nodejs googleapis calendar.events关键问题,node.js,google-api,google-calendar-api,Node.js,Google Api,Google Calendar Api,我正在尝试使用nodejs-googleapis包从用户日历中获取事件。我正在使用passport让用户登录Google,并使用以下范围: scope = [ 'https://www.googleapis.com/auth/calendar', 'https://www.googleapis.com/auth/calendar.readonly', 'https://www.googleapis.com/auth/userinfo.profile', 'profile',

我正在尝试使用nodejs-googleapis包从用户日历中获取事件。我正在使用passport让用户登录Google,并使用以下范围:

scope = [
  'https://www.googleapis.com/auth/calendar',
  'https://www.googleapis.com/auth/calendar.readonly',
  'https://www.googleapis.com/auth/userinfo.profile',
  'profile',
  'email'
],
这一切似乎都很好,passport接收令牌、配置文件等…因此,我尝试获取日历事件,如下所示:

module.exports = (token) => {
    const calendar = google.calendar({
      version: 'v3',
      auth: token
    });

  return new Promise((resolve, reject) => {
    calendar.events.list({
      calendarId: 'primary',
      timeMin: (new Date()).toISOString(),
      maxResults: 10,
      singleEvents: true,
      orderBy: 'startTime',
    }, (err, events) => {
      if (err) {
        console.log(err);
        return reject(err);
      }

      resolve(events);
    });
  });
};
传递到该函数的
token
是我在passport登录期间获得的
accessToken
。在此之后,我得到的错误是:

0|www      |   errors:
0|www      |    [ { domain: 'usageLimits',
0|www      |        reason: 'keyInvalid',
0|www      |        message: 'Bad Request' } ] }

现在,很明显,这表明我没有正确地使用密钥,但我能找到的示例显示,在最初调用
google.calendar
时传递访问令牌。你知道我可能忽略了什么吗?记录令牌确实会在控制台中生成正确的令牌,因此令牌会正确地进入控制台。谢谢你

问题是我没有正确地实现刷新令牌的使用。我现在使用的模式是使用refreshToken在每个请求中获取一个新的令牌

不确定这是否有帮助,但是你能试试这个github repo吗?它提到了使用PassportJS和Calendar API?我能得到它的代码吗?我也在使用Passport和Calendar APi