2016-10-06 9 views
0

が欠落イベントの日付、私はこのようないくつかのPHPコードがあります。GoogleのAPIのPHPクライアントおよびサービスアカウント:

$service = new Google_Service_Calendar($client); 

$calendarId = 'your calendar id'; 
$optParams = array(
    'timeMin' => date('c'), 
    'maxResults' => 100, 
    'singleEvents' => TRUE, 
); 

$results = $service->events->listEvents($calendarId, $optParams); 
$events = $results->getItems(); 

// in order to use it in javascript 
echo json_encode($events); 

$イベントは、予想される配列であるが、各イベントの日付が含まれていません。私はサービスアカウントを利用する前にいくつかのテストを行い、それぞれの日付はプロパティ "start"でアクセス可能でしたが、現在はリストにはありません。私が応答として得るべきものについての適切な文書がないので、任意のアイデアですか? btw。カレンダー設定でサービスアカウントの共有権限を変更しても役立たない。

答えて

0

私はこれを理解しました。私は混乱していましたが、これに関する文書は少なくとも私にとってはかなり混乱しています。

$イベントは確かに正しいリストですが、ドキュメントに記載されているすべてのプロパティが含まれていない理由は、メソッド呼び出しによっていくつかのプロパティを取得する必要があることです。だから私たちは何をする必要があります:

// start of first event 
$startDate = $events[0]->getStart(); 

これは私のスクリプト全体のようになります。私のPHPの言い訳、それ以前にそれを使用したことがない

<?php 

    header('Content-type: application/json'); 

    include_once __DIR__ . '/vendor/autoload.php'; 

    $client = new Google_Client(); 

    $client->setAuthConfig('your service account json secret'); 

    $client->setApplicationName('your application name'); 
    $client->setScopes(['https://www.googleapis.com/auth/calendar.readonly']); 
    $service = new Google_Service_Calendar($client); 

    // make actual request 
    $calendarId = 'your calendar id'; 
    $optParams = array(
     'timeMin' => date('c'), 
     'maxResults' => 100, 
     'singleEvents' => TRUE, 
     'orderBy' => 'startTime', 
    ); 

    // of type Events.php 
    $events = $service->events; 

    // list of items of type Event.php 
    $eventItems = $events->listEvents($calendarId, $optParams)->getItems(); 

    // compose an result object, we're only interested in summary, location and dateTime atm 
    // don't know if this is considered proper php code, works though 
    $result = array(); 
    for ($i = 0; $i < count($eventItems); $i++) 
    { 
     $result[$i]->{summary} = $eventItems[$i]->getSummary(); 
     $result[$i]->{location} = $eventItems[$i]->getLocation(); 
     $result[$i]->{startDate} = $eventItems[$i]->getStart()->getDateTime(); 
    } 

    echo json_encode($result); 

?> 
関連する問題