the*_*wts 9 google-api-php-client
我一直在寻找几天,并尝试新的和旧版本的google-api-php-client以及各种其他示例,但我似乎无法绕过这个错误.下面的代码是从GitHub检索到的服务帐户示例,我从API控制台中删除了我的凭据和文件.我有一个我正在构建的不同文件,但是为了在这个问题中使用,我认为这个更简单的文件会更容易讨论.我对这两个文件都有同样的错误.
致命错误:未捕获的异常'Google_Auth_Exception',消息'无法解析p12文件.这是一个.p12文件吗?密码是否正确?OpenSSL错误:第52行的/google-api-php-client/src/Google/Signer/P12.php
我完全不知道为什么会抛出这个错误.
我已经验证"file_get_contents"实际上是获取文件的内容,我的"notasecret"密码正在被正确拉出.我希望这个最近的提交可能有所帮助,但不幸的是,它并没有为我解决这个错误.
知道这里出了什么问题吗?谢谢你的任何建议!
<?php
session_start();
include_once "templates/base.php";
set_include_path("../src/" . PATH_SEPARATOR . get_include_path());
require_once 'Google/Client.php';
require_once 'Google/Service/Books.php';
$client_id = 'xxxx.apps.googleusercontent.com';
$service_account_name = 'xxxx@developer.gserviceaccount.com';
$key_file_location = 'xxxx-privatekey.p12';
echo pageHeader("Service Account Access");
if ($client_id == 'xxxx.apps.googleusercontent.com'
|| !strlen($service_account_name)
|| !strlen($key_file_location)) {
echo missingServiceAccountDetailsWarning();
}
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$service = new Google_Service_Books($client);
if (isset($_SESSION['service_token'])) {
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/books'),
$key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
$optParams = array('filter' => 'free-ebooks');
$results = $service->volumes->listVolumes('Henry David Thoreau', $optParams);
echo "<h3>Results Of Call:</h3>";
foreach ($results as $item) {
echo $item['volumeInfo']['title'], "<br /> \n";
}
echo pageFooter(__FILE__);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10925 次 |
| 最近记录: |