node.js - 有没有办法授予我的nodejs应用程序访问我的谷歌日历的权限?

标签 node.js google-api google-calendar-api google-apis-explorer google-api-nodejs-client

所以我有一个nodejs应用程序,它向某些人发送谷歌日历中的事件邀请,现在我正在使用我的gmail帐户和OAuth Playground来获取临时访问 token ,它可以工作,但访问 token 只是可用的几分钟后,每次我需要手动刷新访问 token 并授予对我的谷歌帐户日历的访问权限,这就是问题所在,现在我想在不干扰该过程的情况下使某些内容动态化。 该应用程序托管在 wix 中。 有什么建议 ? 谢谢

最佳答案

如果您只允许他们访问您拥有和控制的日历,那么您可以使用服务帐户。

let google = require('googleapis');
let privatekey = require("./privatekey.json");
  Now let’s use the private key to configure a JWT auth client and authenticate our request.
    // 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);
       return;
     } else {
       console.log("Successfully connected!");
     }
    });

在 Google 开发者控制台中创建服务帐户凭据。然后获取服务帐户电子邮件地址并通过谷歌日历网站与其共享日历。您拥有的其余代码应该是相同的,只需用此替换 auth 部分即可。

关于node.js - 有没有办法授予我的nodejs应用程序访问我的谷歌日历的权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60929631/

相关文章:

google-api - 错误: restricted_client when authorization Youtube API V3

google-calendar-api - 在什么情况下,iCal VEVENT 可能会出现重复的 UID?

node.js - express 路线参数条件

node.js - Socket.io - 发送到套接字 ID 数组

Node.js 的 PHP 包函数替代方案

javascript - Nodejs path.resolve 未定义

java - 从 GoogleIdToken 获取用户个人资料

php - 用于动态 IP 服务器的 Google API key

java - 如何从谷歌日历中的辅助日历中获取数据?

google-calendar-api - Google Calendar API事件插入始终返回404 “not found”错误