2012-06-19 77 views
-1

我試着去創建「服務帳戶」日曆應用程序,我下載了谷歌的API的PHP客戶端谷歌日曆API - 服務帳戶錯誤

的最新版本,然後當我訪問serviceAccount.php我得到以下錯誤:

致命錯誤:調用未定義方法apiClient :: setAssertionCredentials()在/home/fmentert/public_html/reservations/google-api-php-client/examples/calendar/serviceAccount.php上線44

這是我的serviceAccount.php文件。我添加了我的客戶端ID,服務帳戶名稱和密鑰文件。 也。我改變常量定義() 我的php版本是5.2.17

define('CLIENT_ID', '896988357842.apps.googleusercontent.com'); 
define('SERVICE_ACCOUNT_NAME', '[email protected]'); 

// Make sure you keep your key.p12 file in a secure location, and isn't 
// readable by others. 
define('KEY_FILE', 'bqwe3287e42d1c2342349f4c9769asdas55-privatekey.p12'); 

$client = new apiClient(); 
$client->setApplicationName("Google Prediction Sample"); 

// Set your cached access token. Remember to replace $_SESSION with a 
// real database or memcached. 
session_start(); 
if (isset($_SESSION['token'])) { 
$client->setAccessToken($_SESSION['token']); 
} 

// Load the key in PKCS 12 format (you need to download this from the 
// Google API Console when the service account was created. 
$key = file_get_contents(KEY_FILE); 
$client->setAssertionCredentials(new apiAssertionCredentials( // THIS IS LINE 44 
    SERVICE_ACCOUNT_NAME, 
    array('https://www.googleapis.com/auth/prediction'), 
    $key) 
); .... 

有誰知道什麼是錯?

+0

您發佈的代碼試圖從錯誤的url中獲取令牌。 https://www.googleapis.com/auth/prediction網址用於預測服務。對於日曆服務,您需要https://www.googleapis.com/auth/calendar。正如下面的迴應指出我們,你需要包括apiClient.php文件,並添加到文件src/contrib/apiCalendarService.php從閱讀你的代碼,我推斷你複製粘貼代碼w/o閱讀筆記或尋找在代碼的邏輯,使您的目的工作 – IberoMedia

回答

0

看起來您不包含包含apiClient類定義的文件。爲此,請使用require_once命令。

例如,如果apiClient類是在一個名爲「apiClientFile.php」文件中定義的,那麼你的PHP腳本應該是這樣的:

require_once 'apiClientFile.php'; 

define('CLIENT_ID', '896988357842.apps.googleusercontent.com'); 
... 
+0

嗨。 我其實也沒有,只是沒有粘貼在這裏,連同上面的所有評論。所以它開始....評論,意見,評論 - > require_once'../../src/apiClient.php'; require_once'../../src/contrib/apiPredictionService.php'; require_once'../../src/contrib/apiPredictionService.php'; 而且我確實在尋找最新版本 –

+0

那麼錯誤消息說它無法在「apiClient」類中找到名爲「setAssertionCredentials」的方法。嘗試打開apiClient.php,看看你是否能找到你需要的方法。這可能是因爲你使用了錯誤的方法名稱。 – Michael

+0

THANX --- Aha。是的,你是對的...我無法在 http://code.google.com/p/google-api-php-client/ 的最新版本中找到setAssertionCredentials當我去「來源「: http://code.google.com/p/google-api-php-client/source/browse/trunk/src/apiClient.php?r=399 我收到正確的文件...但會我必須一個接一個地下載它們......是這個問題嗎? (一個接一個),因爲我現在得到不同的錯誤。 –