在哪里可以找到Google API客户端的certificate.json?

问题描述 投票:0回答:1

Google Calender Node.js示例需要一个名为“ credentials.json”的文件:https://developers.google.com/calendar/quickstart/nodejs

相关代码:

// Load client secrets from a local file.
fs.readFile('credentials.json', (err, content) => {
  if (err) return console.log('Error loading client secret file:', err);
  // Authorize a client with credentials, then call the Google Calendar API.
  authorize(JSON.parse(content), listEvents);
});
function authorize(credentials, callback) {
  const {client_secret, client_id, redirect_uris} = credentials.installed;
  const oAuth2Client = new google.auth.OAuth2(
      client_id, client_secret, redirect_uris[0]);

  // Check if we have previously stored a token.
  fs.readFile(TOKEN_PATH, (err, token) => {
    if (err) return getAccessToken(oAuth2Client, callback);
    oAuth2Client.setCredentials(JSON.parse(token));
    callback(oAuth2Client);
  });
}

我不知道在哪里可以找到该文件。 Google API控制台提供了“下载JSON”选项,但是文件格式不正确,并且缺少redirect_uris字段。

node.js google-api google-calendar-api google-api-client
1个回答
0
投票
  • 您要检索credentials.json文件以将Google API与Node.js的快速入门一起使用。

如果我的理解是正确的,那么这个答案怎么样?请认为这只是几个答案之一。

在此答案中,假定您单击了“启用Google Calendar API”按钮。

流量:

  1. 当您单击“启用Google Calendar API”按钮时,可以看到以下屏幕。在这里,请单击“ API控制台”。

    • enter image description here
  2. 当您单击“ API控制台”时,可以看到以下屏幕。在这里,请单击“凭据”。

    • enter image description here
  3. 单击“凭据”时,可以看到以下屏幕。在这里,请点击下载按钮。这样,您可以检索JSON文件。此时,请将文件重命名为credentials.json,并将其放置在具有Node.js快速入门要使用的路径的目录中。

    • enter image description here

注意:

  • 如果需要创建新的Cloud Platform Project,则this information可能会有用。

参考:

如果我误解了你的问题,而这不是你想要的方向,我深表歉意。

© www.soinside.com 2019 - 2024. All rights reserved.