我正在嘗試使用 Google 日歷 API 創建 Google 日歷事件。具體來說,我正在使用服務帳戶方法,因為我的應用程序將運行一系列事件以創建并將它們插入到我的 Google 日歷中。使用的語言是 PHP。我已經從 gitHub 下載了 PHP 客戶端庫。 https://github.com/googleapis/google-api-php-client。我的測試代碼如下。這成功完成并返回一個長事件 ID。但是,當我嘗試將其粘貼到我的瀏覽器中時,它會將我帶到我的日歷并顯示“找不到請求的事件”。2020 年 5 月 28 日也沒有任何顯示。誰能讓我明白我做錯了什么?C:/sites/GoogleCredentials/service-account.json 中的文件是我在 Google Cloud Console 項目下創建的憑據中的服務帳戶密鑰。require_once('google-calendar/vendor/autoload.php'); putenv('GOOGLE_APPLICATION_CREDENTIALS=C:/sites/GoogleCredentials/service-account.json'); $client = new Google_Client(); $client->useApplicationDefaultCredentials(); $client->addScope(Google_Service_Calendar::CALENDAR_EVENTS); $service = new Google_Service_Calendar($client); $event = new Google_Service_Calendar_Event(array( 'summary' => 'Google I/O 2015', 'location' => '800 Howard St., San Francisco, CA 94103', 'description' => 'A chance to hear more about Google\'s developer products.', 'start' => array( 'dateTime' => '2020-05-28T09:00:00', 'timeZone' => 'America/New_York' ), 'end' => array( 'dateTime' => '2020-05-28T17:00:00', 'timeZone' => 'America/New_York' ) )); $calendarId = 'primary'; $event = $service->events->insert($calendarId, $event); printf('Event created: '.$event->htmlLink);
1 回答

拉丁的傳說
TA貢獻1789條經驗 獲得超8個贊
您需要記住服務帳戶不是您。服務帳戶有自己的谷歌日歷帳戶。這些事件被插入到它的谷歌日歷中,而不是你的。
您應該使用服務帳戶電子郵件地址與服務帳戶共享您的日歷,然后使用日歷中的日歷 ID 插入。
您也可以保留原樣,并確保邀請自己參加服務帳戶舉辦的活動。
- 1 回答
- 0 關注
- 166 瀏覽
添加回答
舉報
0/150
提交
取消