尝试实现 NodeJS Gmail API 示例

Trying to implement NodeJS Gmail API example

我正在尝试运行 NodeJs Gmail API 快速入门示例。起初,我能够得到示例 运行 并收到如下所示的输出。

INBOX
SPAM
ETC ...

之后我做了一些更改,以便我可以看到消息等。发生这种情况后,我在提示后开始收到以下错误(之前可以正常工作)。

Authorize this app by visiting this url: https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fgmail.modify&response_type=code&client_id=***&redirect_uri=***
Enter the code from that page here:

我收到此错误代码

Error retrieving access token GaxiosError: invalid_grant
    at Gaxios.<anonymous> (C:\***\node_modules\gaxios\build\src\gaxios.js:73:27)
    at Generator.next (<anonymous>)
    at fulfilled (C:\***\node_modules\gaxios\build\src\gaxios.js:16:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  response: {
    config: {
      method: 'POST',
      url: 'https://oauth2.googleapis.com/token',
      data: 'code=***client_id=***&client_secret=***&redirect_uri=http***=authorization_code&code_verifier=',
      headers: [Object],
      params: [Object: null prototype] {},
      paramsSerializer: [Function: paramsSerializer],
      body: 'code=***&client_id=***&client_secret=***&redirect_uri=***&grant_type=authorization_code&code_verifier=',
      validateStatus: [Function: validateStatus],
      responseType: 'json'
    },
    data: {
      error: 'invalid_grant',
      error_description: 'Malformed auth code.'
    },
    headers: {
    ***,
    ***
    },
    status: 400,
    statusText: 'Bad Request'
  },
  config: {
    method: 'POST',
    url: 'https://oauth2.googleapis.com/token',
    data: 'code=***&client_id=***&client_secret=***&redirect_uri=***=authorization_code&code_verifier=',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'User-Agent': 'google-api-nodejs-client/3.1.2',
    },
    params: [Object: null prototype] {},
    paramsSerializer: [Function: paramsSerializer],
    body: 'code=***&client_id=***&client_secret=***&redirect_uri=***&grant_type=authorization_code&code_verifier=',
    validateStatus: [Function: validateStatus],
    responseType: 'json'
  },
  code: '400'
}

所以我将更改恢复为原来的快速入门代码,但仍然出现上述错误。我不知道为什么会这样,希望得到帮助!

Gmail api 的作品在您使用后很快就会过期

尝试删除 credentials.json 并重新启动脚本。