亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 GSuite 域中創建輔助日歷

在 GSuite 域中創建輔助日歷

PHP
藍山帝景 2023-06-24 17:45:29
我創建了一個 GSuite 帳戶,其域名為 redu.club我使用 GSuite 管理員電子郵件創建了一個項目和一個服務帳戶使用共享設置將該服務帳戶添加到管理日歷,并授予完全管理權限。我正在嘗試在 [email protected] 帳戶下創建輔助日歷。這是我的代碼:putenv('GOOGLE_APPLICATION_CREDENTIALS=' . __DIR__ . '/redu-service-account.json');define('SCOPES', Google_Service_Calendar::CALENDAR);function createCalendar(){    try {        // Create and configure a new client object.                $client = new Google_Client();        $client->setApplicationName('Redu');        $client->useApplicationDefaultCredentials();        $client->addScope([SCOPES]);        $client->setAccessType('offline');        $service = new Google_Service_Calendar($client);        // Calendar creation        $calendar = new Google_Service_Calendar_Calendar();        $calendar->setSummary('test');        $calendar->setTimeZone('America/Los_Angeles');        $createdCalendar = $service->calendars->insert($calendar);        // Make the newly created calendar public        $rule = new Google_Service_Calendar_AclRule();        $scope = new Google_Service_Calendar_AclRuleScope();        $scope->setType("default");        $scope->setValue("");        $rule->setScope($scope);        $rule->setRole("reader");        $createdRule = $service->acl->insert($createdCalendar->getId(), $rule);        return $createdCalendar->getId();    } catch (Exception $e) {        print "An error occurred: " . $e->getMessage();    }}此代碼創建了一個日歷,但是當我轉到 [email protected] 的日歷時,我看不到它。我的猜測是它正在服務帳戶下創建一個日歷。當我嘗試添加行時 $this->client->setSubject('[email protected]');,得到的錯誤是:Fatal error: Uncaught exception 'Google_Service_Exception' with message '{  "error": "unauthorized_client",  "error_description": "Client is unauthorized to retrieve access tokens using this method, or client not authorized for any of the scopes requested."任何幫助是極大的贊賞。
查看完整描述

1 回答

?
慕妹3242003

TA貢獻1824條經驗 獲得超6個贊

如果要為用戶創建輔助日歷,則需要模擬該用戶

您已經正確嘗試過:

? ? ? $client = new Google_Client();

? ? ? ? $client->setApplicationName('Redu');

? ? ? ? $client->useApplicationDefaultCredentials();

? ? ? ? $client->addScope([SCOPES]);

? ? ? ? $client->setAccessType('offline');

? ? ? ? $client->setSubject('[email protected]');

? ? ? ? $service = new Google_Service_Calendar($client);

但之前需要遵循兩個重要步驟:

  1. 在 GCP 控制臺中為服務帳號啟用域范圍委派

  2. 在管理控制臺中為服務帳號提供必要的委派范圍


查看完整回答
反對 回復 2023-06-24
  • 1 回答
  • 0 關注
  • 114 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號