【发布时间】:2018-02-10 05:58:50
【问题描述】:
我正在尝试通过 google 日历 API 使用服务器到服务器的身份验证。在他们提到的文档中,您可以模拟用户。我已向要模拟的帐户添加所有者权限,并确保启用了域范围的委派。从我读过的所有内容中,“user@example”应该指定模仿者,但它不起作用。我拥有创建事件等的所有功能,但我无法通过谷歌随机生成的电子邮件以外的电子邮件获得它。
var google = require('googleapis');
var calendar = google.calendar('v3');
var scopes = ['https://www.googleapis.com/auth/calendar'];
var key = require ('./xxx.json'); // private json
console.log("Calendar Service connected");
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
scopes,
'user@example.com'
);
jwtClient.authorize(function(err, token) {
if(err) {
//console.log(err);
}
console.log('token',token);
//listCalendars(jwtClient);
});
module.exports = {};
感谢您的帮助!!
【问题讨论】:
-
您可能希望遵循此reported issue 中的可能解决方案。您可能以不同的方式实现了您的代码,并确保为您的服务帐户启用域范围委派。希望这会有所帮助。
标签: node.js jwt google-calendar-api