gpt4 book ai didi

google-api-php-client - 使用google-api-php-client获取 "Unable to parse the p12 file..."错误

转载 作者:行者123 更新时间:2023-12-04 04:11:21 24 4
gpt4 key购买 nike

我一直在寻找几天,并尝试使用新旧版本的google-api-php-client以及其他各种示例,但似乎无法解决此错误。
下面的代码是从GitHub检索的服务帐户示例,我从API控制台中放入了凭据和文件。我实际上正在构建一个不同的文件,但是对于这个问题,我认为这个更简单的文件将更易于讨论。我在两个文件中都遇到了相同的错误。

Fatal error: Uncaught exception 'Google_Auth_Exception' with message 'Unable to parse the p12 file. Is this a .p12 file? Is the password correct? OpenSSL error: ' in /google-api-php-client/src/Google/Signer/P12.php on line 52



我完全为为什么它会引发此错误而感到困惑。

我已验证“file_get_contents”实际上正在获取文件的内容,并且我的“notasecret”密码已正确提取。我希望 this recent commit可能会有所帮助,但不幸的是,它没有为我解决此错误。

知道这里出了什么问题吗?感谢您的任何建议!
<?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__);

最佳答案

我也遇到了此错误,就我而言,问题是.p12文件仅对所有者拥有读取权限,而对组和其他人没有访问权限。我为此花了2天的时间...

现在,我收到错误消息“用户对此配置文件没有足够的权限”,但至少是新内容!

关于google-api-php-client - 使用google-api-php-client获取 "Unable to parse the p12 file..."错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22079057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com