我试着去创建“服务帐户”日历应用程序,我下载了谷歌的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