使用目录获取资源日历 API
Get Resource Calendar with Directory API
我真的试过了,但我自己搞不懂如何用目录检索资源日历的数据API。
我想要的:
- 使用具有全域委托的服务帐户检索我公司资源日历的数据
我有:
具有全域委派的服务帐户 (+ credentials.json)
我公司资源日历的日历ID
我是非管理员用户,据我所知,服务帐户必须模拟用户。
我是否需要成为管理员用户才能管理和查看资源日历的数据并与服务帐户共享?
我使用 jwtClient 进行授权,但我不知道是否必须使用目录 API、Google 日历 API 或两者才能使其正常工作。
我首先尝试使用 Google 日历 API,但没有用,现在我想我必须通过目录 API 获取资源日历。
这就是我到目前为止所拥有的:
let express = require('express');
let app = express();
app.set('view engine', 'ejs');
let {google} = require('googleapis');
const calendar = google.calendar('v3');
const port = 3000;
const key = require('./credentials.json');
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
[ 'https://www.googleapis.com/auth/calendar'],
null
);
jwtClient.authorize(function(err, tokens) {
if (err) {
console.log(err);
} else {
console.log("Authorization worked!");
console.log(tokens);
}
});
app.get('/', function(req, res) {
calendar.events.list({
auth: jwtClient,
calendarId: 'xxxx@resourcexxx.com',
timeMin: (new Date()).toISOString(),
maxResults: 5,
singleEvents: true,
orderBy: 'startTime'
}, function(err, resp) {
res.json(resp);
});
});
app.use(express.static('public'));
app.listen(port, function(err){
if (!err) {
console.log("App is running on port", port);
} else {
console.log(JSON.stringify(err));
}
});
如有任何帮助,我们将不胜感激。提前致谢!
I'm a non-admin user and as far as I know the service account has to impersonate a user. Do I need to be an admin user to manage and see the data of the resource calendar and share it with the service account?
服务帐户 可以 模拟用户,当他们启用了全域委派时。没必要。
服务帐户的行为类似于 "normal" 帐户 - 它们对资源拥有自己的权限。这意味着,如果您想从该帐户获取特定日历的数据,则必须授予它查看权限。如果您希望使用服务帐户对其进行编辑,则必须授予该帐户编辑权限。您可以像对待任何其他用户一样这样做,不同之处在于您必须使用服务帐户的电子邮件地址(您可以在开发人员的控制台中找到)来引用它。
如果您使用的是启用了域范围身份验证的服务帐户,则在进行身份验证时,您可以指定 "subject"(您域中的现有用户)来模拟。身份验证成功后,执行的每个操作都将被执行,就好像 "subject" 帐户是执行它们的帐户一样 - 并且它将使用该用户的权限。
I use a jwtClient to authorize and I have no idea whether I have to use the Directory API, Google Calendar API or both to make it work.
- 由于您是从日历中检索数据(而不是任何用户的信息),因此您只需要使用 Google Calendar API.
What I want: retrieve the data of my company's resource calendar by using a service account with domain-wide delegation
- 在您的情况下 - 检索数据 - 您可以简单地与您的服务帐户共享该日历。之后,无需使用全域委托,它将能够使用
calendar.events.list
检索日历中存在的事件及其详细信息,使用您提供的相同代码。
参考
我真的试过了,但我自己搞不懂如何用目录检索资源日历的数据API。
我想要的:
- 使用具有全域委托的服务帐户检索我公司资源日历的数据
我有:
具有全域委派的服务帐户 (+ credentials.json)
我公司资源日历的日历ID
我是非管理员用户,据我所知,服务帐户必须模拟用户。 我是否需要成为管理员用户才能管理和查看资源日历的数据并与服务帐户共享? 我使用 jwtClient 进行授权,但我不知道是否必须使用目录 API、Google 日历 API 或两者才能使其正常工作。
我首先尝试使用 Google 日历 API,但没有用,现在我想我必须通过目录 API 获取资源日历。 这就是我到目前为止所拥有的:
let express = require('express');
let app = express();
app.set('view engine', 'ejs');
let {google} = require('googleapis');
const calendar = google.calendar('v3');
const port = 3000;
const key = require('./credentials.json');
const jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
[ 'https://www.googleapis.com/auth/calendar'],
null
);
jwtClient.authorize(function(err, tokens) {
if (err) {
console.log(err);
} else {
console.log("Authorization worked!");
console.log(tokens);
}
});
app.get('/', function(req, res) {
calendar.events.list({
auth: jwtClient,
calendarId: 'xxxx@resourcexxx.com',
timeMin: (new Date()).toISOString(),
maxResults: 5,
singleEvents: true,
orderBy: 'startTime'
}, function(err, resp) {
res.json(resp);
});
});
app.use(express.static('public'));
app.listen(port, function(err){
if (!err) {
console.log("App is running on port", port);
} else {
console.log(JSON.stringify(err));
}
});
如有任何帮助,我们将不胜感激。提前致谢!
I'm a non-admin user and as far as I know the service account has to impersonate a user. Do I need to be an admin user to manage and see the data of the resource calendar and share it with the service account?
服务帐户 可以 模拟用户,当他们启用了全域委派时。没必要。
服务帐户的行为类似于 "normal" 帐户 - 它们对资源拥有自己的权限。这意味着,如果您想从该帐户获取特定日历的数据,则必须授予它查看权限。如果您希望使用服务帐户对其进行编辑,则必须授予该帐户编辑权限。您可以像对待任何其他用户一样这样做,不同之处在于您必须使用服务帐户的电子邮件地址(您可以在开发人员的控制台中找到)来引用它。
如果您使用的是启用了域范围身份验证的服务帐户,则在进行身份验证时,您可以指定 "subject"(您域中的现有用户)来模拟。身份验证成功后,执行的每个操作都将被执行,就好像 "subject" 帐户是执行它们的帐户一样 - 并且它将使用该用户的权限。
I use a jwtClient to authorize and I have no idea whether I have to use the Directory API, Google Calendar API or both to make it work.
- 由于您是从日历中检索数据(而不是任何用户的信息),因此您只需要使用 Google Calendar API.
What I want: retrieve the data of my company's resource calendar by using a service account with domain-wide delegation
- 在您的情况下 - 检索数据 - 您可以简单地与您的服务帐户共享该日历。之后,无需使用全域委托,它将能够使用
calendar.events.list
检索日历中存在的事件及其详细信息,使用您提供的相同代码。