2012-06-19 49 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 我收到正确的文件...但会我必须一个接一个地下载它们......是这个问题吗? (一个接一个),因为我现在得到不同的错误。 –