如何使用Node.js使用服务帐号连接到Google日历API?
<p>如何在使用Node.js时使用Google Auth客户端。</p>
<p>我查阅了许多文章,客户端URL将提供一个代码数据,我可以使用它来获取客户端详细信息。但是,我如何使用服务客户端代表客户自动进行身份验证。我主要需要获取Google Meet链接并添加到客户的Google日历中。</p>
<p>我正在遵循这段代码。但这是手动URL身份验证。</p>
<p>https://github.com/isuruhettiarachchi/ssd-oauth-assignment/blob/master/utils/google-util.js</p>
尝试类似以下的操作,确保从您的工作区帐户向服务帐户配置域范围委派。
subject是您希望服务帐户模拟的域上的用户。
let google = require('googleapis'); let privateKey = require("./privatekey.json"); var jwtClient = new google.auth.JWT({ email: privateKey.client_email, key: privateKey.private_key, scopes: ['https://www.googleapis.com/auth/calendar'], subject: 'user@domain.com' }); jwtClient.authorize(function (error, tokens) { if (error) { console.log(error); return; } else { console.log("Successfully connected!"); } });