Roy*_*son 7 google-calendar-api google-api node.js google-api-client
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);
});
}
Run Code Online (Sandbox Code Playgroud)
我不知道在哪里可以找到这个文件。Google API 控制台提供了“下载 JSON”选项,但文件格式不正确且缺少该redirect_uris
字段。
Tan*_*ike 12
credentials.json
通过 Node.js 的 Quickstart检索使用 Google API 的文件。如果我的理解是正确的,这个答案怎么样?请将此视为几个答案之一。
在此答案中,假设您单击了“启用 Google 日历 API”按钮。
当您单击“启用 Google 日历 API”按钮时,可以看到以下屏幕。在这里,请点击“API 控制台”。
当您单击“API 控制台”时,可以看到以下屏幕。在这里,请单击“凭据”。
当您单击“凭据”时,可以看到以下屏幕。在这里,请点击下载按钮。这样,您就可以检索 JSON 文件。此时,请将文件重命名为credentials.json
,并放到 Node.js 快速入门使用的路径所在的目录中。
如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
归档时间: |
|
查看次数: |
10898 次 |
最近记录: |