如何使用PHP将事件插入私人Google日历?

时间:2015-11-13 15:06:42

标签: php google-calendar-api google-oauth

我尝试在我的私人Google日历中添加新活动,但我收到(403)禁止消息。我在互联网上搜索过,但我找不到答案。

我的范围设置为读/写,凭据应该没问题,因为我可以读出所有事件,因此连接正常。

以下是代码:

$service_account = $this->service_account;
$json_key = json_decode(file_get_contents($this->json_url));
$scopes = 'https://www.googleapis.com/auth/calendar';
$application_name = 'Calendar';

$client = new Google_Client();
$client->setApplicationName($application_name);
$cred = new Google_Auth_AssertionCredentials($service_account, array($scopes), $json_key->private_key);
$client->setAssertionCredentials($cred);

if($client->getAuth()->isAccessTokenExpired()) {        
    $client->getAuth()->refreshTokenWithAssertion($cred);       
}

$google_service = new Google_Service_Calendar($client);


$calendar_ids = $this->calendar_ids;
$event = new Google_Service_Calendar_Event();


$event->setSummary($service);
$event->setDescription($user);
$event->setLocation($location);
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime($this->sqlDateToGcalDate($start_date));
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime($this->sqlDateToGcalDate($end_date));
$event->setEnd($end);

$google_service->events->insert($calendar_ids[$steed], $event);
$google_service->events->insert($calendar_ids[$location], $event);

0 个答案:

没有答案