2
基本破壞:我已經編寫了一個客戶端日曆,允許人們安排約會和預約時間段(例如,預訂會記錄在數據庫和第二個人不能選擇相同的時間段),以方便在供應商方面聯合和打印這些約會,他們要求我將這些事件推送到單個Google日曆。我已經爲它創建了一個Google帳戶和一個日曆,然後創建了API密鑰,並在該Google用戶下訪問了Calendar API。所以我希望我的網站每次都使用此用戶的憑證來創建活動。看起來這將是一個「服務帳戶」,但似乎無法訪問用戶數據,甚至不是創建該應用程序的用戶。Google Calendar API v3 PHP - >嘗試將新事件創建爲單個日曆
如何退出這個功能的任何想法?如果它看起來應該是令人震驚的簡單,並且我不是第一個想要做這樣的事情的人,但是如果我能找到它的任何例子就該死。
下面的代碼
$event = new Google_Event();
$event->setSummary($title);
$event->setLocation($location);
$start = new Google_EventDateTime();
$start->setDateTime($date . 'T' . $startTime . ':00.000-06:00');
$event->setStart($start);
$end = new Google_EventDateTime();
$end->setDateTime($date . 'T' . $endTime . ':00.000-06:00');
$event->setEnd($end);
$attendee1 = new Google_EventAttendee();
$attendee1->setEmail($email);
$attendees = array($attendee1);
$event->attendees = $attendees;
$client = new Google_Client();
$service = new Google_CalendarService($client);
$createdEvent = $service->events->insert('my calendar ID', $event);
和錯誤
Uncaught exception 'Google_ServiceException' with message 'Error calling POST https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=AIzaSyAfSCfLJCMSkGRmjZXRtChPPcMNmEuCZow: (401) Login Required' in /home/mydomain.com/wp-content/themes/mytheme/libs/gAPI/io/Google_REST.php:66
謝謝Max。我使用REST API。我的最終代碼是[here](http://pastebin.com/rr4AMaHP) – scH