Getting “Unable to parse the p12 file…” Error With google-api-php-client

我怕爱的太早我们不能终老 提交于 2019-11-29 13:27:12

I suffered this error too, in my case the problem was the .p12 file had read permission only for the owner and no access for group and others. I spent 2 days of my life for this...

Now I get the error "User does not have sufficient permissions for this profile" but at least is something new!!

I just stumbled into the same problem. Converting the p12 file to .pem (as theonlynewts suggested) didn't work for me. There was no "---BEGIN RSA PRIVATE KEY---" section within the .pem file

But strange enough, while this doesn't work (original code from Google's P12.php):

if (!openssl_pkcs12_read( $p12, $certs, $password)) { ...

This DOES work:

$pkcs12 = file_get_contents( $p12 );
if (!openssl_pkcs12_read( $pkcs12, $certs, $password)) { ...

(Tested on PHP 5.5.9 on Kubuntu 14.04)

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.

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.

I'm pretty sure you need to write the phrase 'notasecret' somewhere in this section of code:

$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
    $service_account_name,
    array('https://www.googleapis.com/auth/books'),
    $key
);

'Where?', is the question...

This looks like it has the correct code: https://github.com/google/google-api-php-client/blob/master/src/Google/Auth/AssertionCredentials.php

I will update my answer to confirm this works once I have tested it.

:)

It's usually just a file permissions issue. make sure that the user running apache has permissions to read the p12 file.

I was also stumbled while parsing p12 file. It always showed error like "Undefined function openssl_pkcs12_read()". To get Rid of this error, first you must check php.ini file. open php.ini fine then search for openssl and then uncomment the line. Now save and restart all wamp services.

And your function is working.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!