得到“无法解析p12文件..."; google-api-php-client错误 [英] Getting "Unable to parse the p12 file..." Error With google-api-php-client

查看:97
本文介绍了得到“无法解析p12文件..."; google-api-php-client错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been searching for days and trying new and older version of google-api-php-client along with various other examples out there, but I can't seem to get around this error. The code below is the service-account example retrieved from GitHub and I dropped in my credentials and file from the API Console. I've got a different file I'm actually building, but for use in this question, I figure this simpler file would be easier to discuss. I'm getting the same error with both files.

致命错误:消息无法解析p12文件"的未捕获异常"Google_Auth_Exception".这是.p12文件吗?密码正确吗? OpenSSL错误:"/google-api-php-client/src/Google/Signer/P12.php在第52行上

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

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

I'm completely stumped about why it is throwing this error.

我已验证"file_get_contents"实际上正在获取文件的内容,并且我的"notasecret"密码已正确提取.我希望这最近的提交可能会有所帮助,但不幸的是,它没有为我解决这个错误.

I've verified "file_get_contents" is actually getting the contents of the file and my "notasecret" password is getting pulled properly. I was hoping this recent commit might help, but unfortunately, it didn't solve this error for me.

你知道这里出了什么问题吗?谢谢您的任何建议!

Any idea what is going wrong here? Thank you for any suggestions!

<?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__);

推荐答案

知道了! 此提交让我想到也许openssl不喜欢我们的归档.我使用这些说明将文件从p12转换为pem. .然后,我编辑了该文件,以删除"----- BEGIN RSA PRIVATE KEY -----"之前的一些文本,以便新提交中的代码可以正确识别它.将该文件放入其中,得到的结果就像魔术一样.

Got it! This commit got me thinking that maybe openssl didn't like our file either. I converted my file from a p12 to a pem using these instructions. Then I edited the file to remove some text before the "-----BEGIN RSA PRIVATE KEY-----" so the code from the new commit would recognize it properly. Dropped that file in and got results like magic.

就是这样!我仍然不确定是什么原因导致自动生成的p12文件不配合,所以请让我知道是否有人有任何想法.

That was it! I'm still not sure what would cause the auto-generated p12 file to not cooperate, so let me know if anyone has any ideas.

这篇关于得到“无法解析p12文件..."; google-api-php-client错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆