google-calendar-api - Google Apps 超级管理员对域用户日历的访问权限
问题描述
我有大量资源日历,我的用户需要根据他们的角色拥有不同程度的访问权限。我正在编写一个应用程序来管理这些 Acl 规则,但还想管理哪些日历出现在最终用户日历提要中(即我不想让他们突然看到所有 130 个资源日历并且必须过滤它们)
我需要使用 CalendarList api 访问,但是当我通过 users//calendarList 而不是 users/me/calendarList 授权超级管理员凭据时,服务返回 404 响应。
我的目标是遍历我的共享日历资源列表,并为每个读者或 freeBusyReader 用户设置他们的 calendarListEntry.hidden 为 true。
解决方案
于是,我发现了答案。为了模拟用户,您必须在初始化服务帐户凭据时将“用户”设置为您希望模拟的电子邮件地址:
public static ServiceAccountCredential Credential(string[] Scopes, string impersonateEmail = null)
{
ServiceAccountCredential cred = ServiceAccountCredential.FromServiceAccountData(credential_stream);
var initializer = new ServiceAccountCredential.Initializer(cred.Id)
{
User = string.IsNullOrEmpty(impersonateEmail)?service_acct:impersonateEmail,
Key = cred.Key,
Scopes = Scopes
};
return new ServiceAccountCredential(initializer);
}
推荐阅读
- javascript - 如何使用 useEffect 钩子实现复杂的 shouldComponentUpdate?
- c# - ExcludeFromCodeCoverage 不适用于 asp.net core 3.1 单元测试项目
- wpf - 如何清除 Xamarin.WPF 中 listviewitem 的奇怪间距?
- python - python如何在excel单元格中粘贴非字母数字字符串
- java - 如何使用 Retrofit2 映射带有 ArrayList 的对象?
- blogger - Blogger 模板中的“super.main”是什么意思
- google-cloud-data-fusion - 在云数据融合中使用 JEXL
- c# - 如何将 2 个 db 调用合并为一个
- java - 如何在字段 /selenium 中逐位输入数字
- windows - 自定义 git 凭据助手无法在 Windows 上进行身份验证