Super Admin服务帐户未找到资源日历。

huangapple go评论63阅读模式
英文:

Super Admin service account not finding resource calendar

问题

我试图列出Google Workspace资源日历中的所有事件,结果要么是"用户未找到",要么是"无效的模拟",这取决于我使用的日历标识符是哪个。相同的代码对于普通用户有效,但对于特定的资源日历无效。

$client = new Client();
$client->setApplicationName($this->getName());
$client->setAuthConfig("{$this->configLocation}/{$this->keyReceiving}"); // 服务帐号JSON密钥
$client->setSubject($resource->getResourceEmail()); // 会议室电子邮件地址
$client->setScopes($this->scopes); // [Calendar::CALENDAR, Calendar::CALENDAR_EVENTS, Directory::ADMIN_DIRECTORY_RESOURCE_CALENDAR]

$calendarService = new Calendar($client);
$events = $calendarService->events->listEvents("primary");

"普通用户"和资源之间的区别在于资源的域为@resource.calendar.google.com,而用户的域为@domain.com,其中域是我的自己的域。这导致"用户未找到"的错误。编辑:所有资源都由与我的服务帐号密钥和域广泛委托的组织拥有。

如果我将主题更改为$resource->getResourceID(),这是一个数字ID而不是电子邮件地址,结果是"无效的模拟"错误。

如果我使用我的超级管理员帐号,我可以列出任何普通用户的日历,但如果我尝试列出资源日历,无论是通过ID还是Email,我都会收到"404未找到"的错误 - 就像日历对象不存在一样。

上述方法是否正确用于列出(以及稍后更新)资源日历事件?

英文:

I'm attempting to list all events from a Google Workspace Resource Calendar which results in either a "user not found" or "invalid impersonation" depending on which calendar identifier I use. The same code works for normal users but not specifically resource calendars.

$client = new Client();
$client->setApplicationName($this->getName());
$client->setAuthConfig("{$this->configLocation}/{$this->keyReceiving}"); // Service Account JSON Key
$client->setSubject($resource->getResourceEmail()); // Conference room email address
$client->setScopes($this->scopes); // [Calendar::CALENDAR, Calendar::CALENDAR_EVENTS, Directory::ADMIN_DIRECTORY_RESOURCE_CALENDAR]

$calendarService = new Calendar($client);
$events = $calendarService->events->listEvents("primary");

The difference between "normal users" and resources is that the domain for resources is @resource.calendar.google.com and users is @domain.com where the domain is my own. This results in a "User not found" error. Edit: All resources are owned by the same organization as my service account key and domain wide delegation is generated for.

If I instead change the subject to $resource->getResourceID() which is a numeric ID instead of an email address it results in a "Invalid impersonation" error.

If I use my own Super Admin account I can list any normal user calendar, but if I attempt to list a resource calendar either by ID or Email I get the error "404 Not Found" - as if the calendar object does not exist.

Is the above approach correct for listing (and later updating) a resource calendar events?

答案1

得分: 1

这个错误出现是因为setSubject()方法正在使用一个资源,这个方法仅用于模拟其他用户以便代表他们执行API调用。

当使用资源日历时,代码告诉Google:“我是这个会议室,请获取我的primary日历”。你可以尝试这样做:

$client->setSubject($adminEmailAddress); // 一个超级管理员的电子邮件地址

...

$events = $calendarService->events->listEvents($resource->getResourceEmail());
英文:

This error appears because the setSubject() method is using a Resource, this method is only used to impersonate other users in order to perform the API call on their behalf.

When using a resource calendar the code is telling Google "I'm this conference room please get my primary calendar". You can try this instead:

$client->setSubject($adminEmailAddress); // A Super admin email address

...

$events = $calendarService->events->listEvents($resource->getResourceEmail());

huangapple
  • 本文由 发表于 2023年3月31日 18:40:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75897583.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定