![](/img/trans.png)
[英]Why am I getting an unknown error when trying to login with a user set-up in AWS-cognito CL?
[英]Why I am getting error “login required” when trying to contact the calendar?
我正在使用Google API日历。 为什么我在下面的脚本中收到此错误消息?
联系日历时出错:需要登录
当前代码:
app.post('/token', function(req, res) {
var code = req.body.code;
console.log(code);
async function asyncCall() {
const { tokens } = await oauth2Client.getToken(code);
oauth2Client.setCredentials(tokens);
console.log(tokens);
}
asyncCall();
oauth2Client.on('tokens', tokens => {
if (tokens.refresh_token) {
console.log(tokens.refresh_token);
}
console.log(tokens.access_token);
console.log('Now lets see');
});
//
addEvents();
function addEvents(auth) {
var event = {
summary: 'Google I/O 2045',
location: '800 Howard St., San Francisco, CA 94103',
description: "A chance to hear more about Google's
developer products.",
start: {
dateTime: '2018-10-28T09:00:00-07:00',
timeZone: 'America/Los_Angeles'
},
end: {
dateTime: '2018-10-28T17:00:00-07:00',
timeZone: 'America/Los_Angeles'
},
recurrence: ['RRULE:FREQ=DAILY;COUNT=2'],
reminders: {
useDefault: false,
overrides: [
{ method: 'email', minutes: 24 * 60 },
{ method: 'popup', minutes: 10 }
]
}
};
//console.log(event)
var calendar = google.calendar('v3');
calendar.events.insert(
{
auth: auth,
calendarId: 'primary',
resource: event
},
function(err, event) {
if (err) {
console.log(
'There was an error contacting the Calendar
service: ' + err
);
return;
}
console.log('Event created: %s', event.htmlLink);
}
);
}
});
auth应该在日历对象中分配给oauth2Client。
重新设计您的addEvents()。 您无需使用auth作为参数来定义addEvents函数。 同样,您必须返回var事件并将其分配给资源。 这应该工作:
app.post('/token', function(req, res) {
var code = req.body.code;
console.log(code);
async function asyncCall() {
const { tokens } = await oauth2Client.getToken(code);
oauth2Client.setCredentials(tokens);
console.log(tokens);
}
oauth2Client.on('tokens', tokens => {
if (tokens.refresh_token) {
console.log(tokens.refresh_token);
}
console.log(tokens.access_token);
console.log('Now lets see');
});
function addEvents() {
var event = {
summary: 'Google I/O 2045',
location: '800 Howard St., San Francisco, CA 94103',
description: "A chance to hear more about Google's
developer products.",
start: {
dateTime: '2018-10-28T09:00:00-07:00',
timeZone: 'America/Los_Angeles'
},
end: {
dateTime: '2018-10-28T17:00:00-07:00',
timeZone: 'America/Los_Angeles'
},
recurrence: ['RRULE:FREQ=DAILY;COUNT=2'],
reminders: {
useDefault: false,
overrides: [
{ method: 'email', minutes: 24 * 60 },
{ method: 'popup', minutes: 10 }
]
}
return event;
};
//console.log(event)
var calendar = google.calendar('v3');
calendar.events.insert(
{
auth: oauth2Client,
calendarId: 'primary',
resource: addEvents()
},
function(err, event) {
if (err) {
console.log(
'There was an error contacting the Calendar
service: ' + err
);
return;
}
console.log('Event created: %s', event.htmlLink);
}
);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.