2016-05-05 33 views
0

ダウンロードスクリプトhereと設定。しかし、私がカレンダーを取得しようとすると、空のリストが返されます。 のアカウントと共有されているすべてのカレンダーリストを取得したいです。 Gmailのアカウントには4つのカレンダーがありますのでご注意ください。私もこれに従いましたinstructionGoogleカレンダーapi CalendarListリスト返信空リスト

**Code** 

$key = file_get_contents($key_file_location); 
$scopes ="https://www.googleapis.com/auth/calendar.readonly"; 
$cred = new Google_Auth_AssertionCredentials(
    $service_account_name, 
    array($scopes), 
    $key 
); 


$client->setAssertionCredentials($cred); 
if ($client->getAuth()->isAccessTokenExpired()) { 
    $client->getAuth()->refreshTokenWithAssertion($cred); 
} 
$_SESSION['service_token'] = $client->getAccessToken(); 
$service = new Google_Service_Calendar($client); 
echo "<br>=======================<br>";  
var_dump($service->calendarList->listCalendarList()); 
echo "<br>=======================<br>";  
?> 

出力

======================= 

object(Google_Service_Calendar_CalendarList)[23] protected 'collection_key' => string 'items' (length=5) protected 'internal_gapi_mappings' => 
    array (size=0) 
     empty public 'etag' => string '"1462447526879000"' (length=18) protected 'itemsType' => string 'Google_Service_Calendar_CalendarListEntry' (length=41) protected 'itemsDataType' => string 'array' (length=5) public 'kind' => string 'calendar#calendarList' (length=21) public 'nextPageToken' => null public 'nextSyncToken' => string 'CJi-3srpwswCEjVhYmNkZWZAc2tpbGxmdWwtY29zaW5lLTEyNDYwNi5pYW0uZ3NlcnZpY2VhY2NvdW50LmNvbQ==' (length=88) protected 'modelData' => 
    array (size=1) 
     'items' => 
     array (size=0) 
      empty protected 'processed' => 
    array (size=0) 
     empty 
======================= 

答えて

0

ファイルは、以下のJSON形式であるときにキーを読み込むためにいくつかの変更があり、正しいコードが

$key = file_get_contents($key_file_location); 
$data = json_decode($key); 

    $scopes = array("https://www.googleapis.com/auth/calendar.readonly","https://www.googleapis.com/auth/calendar"); 
    $cred = new Google_Auth_AssertionCredentials(
     $service_account_name, 
     $scopes, 
     $data->private_key 
    ); 
$client->setAssertionCredentials($cred); 


try { 
    $client->getAuth()->refreshTokenWithAssertion($cred); 
} catch (Exception $e) { 
    $e->getMessage(); 
} 
$calendarList = $service->calendarList->listCalendarList(); 
var_dump($calendarList); 
です
関連する問題