我正在尝试将Google日历与DialogFlow集成在一起,但是我遇到了麻烦。
我在项目的“实现”部分中添加了以下代码,但始终会收到Firebase错误:
TypeError: Cannot read property 'calendar' of undefined
at createEvent (/user_code/index.js:70:27)
at authorize (/user_code/index.js:33:5)
at yourFunctionHandler (/user_code/index.js:122:5)
at WebhookClient.handleRequest (/user_code/node_modules/dialogflow-
fulfillment/src/dialogflow-fulfillment.js:273:44)
代码:
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const fs = require('fs');
const readline = require('readline');
const {google}= require('googleapis');
const { OAuth2Client } = require("google-auth-library");
function authorize(credentials, callback) {
const client_id = "xxxxxxxxx";
const client_secret = "xxxxxxxxx";
const redirect_uris = "xxxxxxxxx";
const oauth2Client = new OAuth2Client(client_id, client_secret, redirect_uris[0]);
oauth2Client.setCredentials(JSON.parse('xxxxxxxxx'));
callback(oauth2Client);
}
function listEvents(auth) {
google.events.list({
auth:auth,
calendarId: 'primary',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime',
}, (err, res) => {
if (err) return console.log('The API returned an error: ' + err);
const events = res.data.items;
if (events.length) {
console.log('Upcoming 10 events:');
events.map((event, i) => {
const start = event.start.dateTime || event.start.date;
console.log(`${start} - ${event.summary}`);
});
} else {
console.log('No upcoming events found.');
}
});
}
是否有任何人可以与我分享的示例,这样我才能理解至少连接到Google API所需的过程?
谢谢
美国
答案 0 :(得分:0)
使用748317
,您可以像这样简单地创建客户端:
googleapis
虽然我看不到任何“ firebase错误”或任何“对话框流”;我想知道为什么您从nodejs quick-start中删除了日历?否决了这个问题,因为它侮辱了我的才智,使其受到如此虚构的问题的挑战-只需将A与B进行比较,您可能就会明白。