使用Google日历API oauth2服务帐户(node.js)

时间:2017-09-01 07:59:09

标签: node.js jwt google-calendar-api

我正在尝试通过Google日历API使用服务器进行服务器身份验证。在他们提到的文档中,您可以冒充用户。我已将所有者权限添加到我要模拟的帐户,并确保已启用域范围委派。从我读过的所有内容来看,用户@示例'应该指定模仿,但它不起作用。我具有创建活动等所有功能,但我无法通过谷歌随机生成的电子邮件获取它。

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 = {};

感谢您的帮助!!

1 个答案:

答案 0 :(得分:0)

对于将来需要此人的人。它开始工作:

1)启用域范围授权 2)将用户添加到服务帐户作为所有者 3)可能最重要的**:继续谷歌管理员并给api访问服务帐户