我試着去創建「服務帳戶」日曆應用程序,我下載了谷歌的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)
); ....
有誰知道什麼是錯?
您發佈的代碼試圖從錯誤的url中獲取令牌。 https://www.googleapis.com/auth/prediction網址用於預測服務。對於日曆服務,您需要https://www.googleapis.com/auth/calendar。正如下面的迴應指出我們,你需要包括apiClient.php文件,並添加到文件src/contrib/apiCalendarService.php從閱讀你的代碼,我推斷你複製粘貼代碼w/o閱讀筆記或尋找在代碼的邏輯,使您的目的工作 – IberoMedia