node.js - 使用 google calendar API oauth2 服务帐户(node.js)模拟用户

标签 node.js jwt google-calendar-api

我正在尝试通过谷歌日历 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 = {};

最佳答案

我在以下时间开始工作:

  1. 启用全域委派
  2. 将用户作为所有者添加到服务帐户
  3. 最重要的是:进入 google admin 并授予 api 访问服务帐户的权限

关于node.js - 使用 google calendar API oauth2 服务帐户(node.js)模拟用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45995671/

相关文章:

android - 为什么不希望将时区偏移量添加到时间(03 :00 to 08:00)

node.js - Lambda 函数错误 : EROFS: read-only file system, 打开 './tmp/test.zip' 进程在完成请求之前退出

node.js - mail-listener2 不起作用

node.js - MongoDB - 两个按顺序更新彼此重叠

node.js - 提取过期的 jwt token 的有效负载

android - 从 android 日历中检索最后添加的事件的数据

javascript - 关于 express 消息。我无法获取我制作的模板

Symfony 4 "code": 401, "message": "Invalid credentials."jwt 认证错误

node.js - 如何在 NextJS SSR 中存储和获取 access_token

node.js - 谷歌日历推送通知 : Unauthorized webhook call