2015-12-15 39 views
-1

我想在網站上顯示我自己的日曆活動詳情。如何訪問我自己的Google日曆而不公開

爲此,我嘗試了使用帶有API密鑰和日曆ID的Google API調用。 但在這期間面臨的問題,我需要使日曆爲「公共」。

一旦我製作日曆,因爲公共活動的詳細信息正在提取,但是當我刪除日曆作爲公共問題發生時,出現錯誤404「未找到」。

我應該如何獲取日曆事件的詳細信息而不將日曆設爲公共日曆。

我使用這個代碼:

var mykey = 'Gtg-rtZdsreUr_fLfhgPfgff'; 
var calendarid = '[email protected]'; 

$.ajax({ 
    type: 'GET', 
    url: encodeURI('https://www.googleapis.com/calendar/v3/calendars/' + calendarid+ '/events?key=' + mykey), 
    dataType: 'json', 
    success: function (response) { 
     console.log(response); 
     //do whatever you want with each 
    }, 
    error: function (response) { 
     //tell that an error has occurred 
    } 
}); 
+0

退房服務帳戶 – DaImTo

回答

0

可以使用的服務帳戶。

服務帳戶的憑證包括 唯一的生成電子郵件地址,客戶端ID以及至少一個公鑰/私鑰對。

https://developers.google.com/api-client-library/php/auth/service-accounts

<?php 

require_once realpath(dirname(__FILE__).'/google-api-php-client/autoload.php'); 

$client_email = '[email protected]'; 
$private_key = file_get_contents('MyProject.p12'); 
$scopes = array('https://www.googleapis.com/auth/sqlservice.admin'); 
$credentials = new Google_Auth_AssertionCredentials(
    $client_email, 
    $scopes, 
    $private_key 
); 

$client = new Google_Client(); 
$client->setAssertionCredentials($credentials); 
if ($client->getAuth()->isAccessTokenExpired()) { 
    $client->getAuth()->refreshTokenWithAssertion(); 
} 

$sqladmin = new Google_Service_SQLAdmin($client); 
$response = $sqladmin->instances 
    ->listInstances('examinable-example-123')->getItems(); 
echo json_encode($response) . "\n"; 
相關問題