我正在尝试创建一个操作,将我自己日历中的信息读取给通过Google智能助理提出要求的任何用户。
请注意,我不希望每个用户都能够访问各自的日历详细信息。但我希望他们能够通过操作访问我的日历详细信息。
我根据找到here
的内容尝试了这个这就是我的尝试,但它从未奏效。你有谁知道为什么?
... //other declarations and stuff
let Assistant = require('actions-on-google').ApiAiAssistant;
... //rest of the code
//Specific action corresponding to the read Calendar intent.
function readCalendarAction (assistant) {
function finalResponse(response){
assistant.ask(response); //final response from fullfillment
}
let google = require('googleapis');
let privatekey = require("./mynewpk.json");
// configure a JWT auth client
let jwtClient = new google.auth.JWT(
privatekey.client_email,
null,
privatekey.private_key,
['https://www.googleapis.com/auth/calendar']);
//authenticate request
jwtClient.authorize(function (err, tokens) {
if (err) {
//console.log(err);
var response = 'This one is an error';
finalResponse(response);
return;
} else {
//console.log("Successfully connected!");
//var response = 'this is the newer answer';
//finalResponse(response);
}
});
//Google Calendar API
let calendar = google.calendar('v3');
calendar.events.list({
auth: jwtClient,
calendarId: 'primary'
}, function (err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var events = response.items;
var response = events[0].summary;
finalResponse(response);
});