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

前端 未结 6 1881
忘了有多久
忘了有多久 2020-12-20 15:02

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 err

相关标签:
6条回答
  • 2020-12-20 15:08

    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)

    0 讨论(0)
  • 2020-12-20 15:16

    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!!

    0 讨论(0)
  • 2020-12-20 15:16

    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.

    :)

    0 讨论(0)
  • 2020-12-20 15:22

    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.

    0 讨论(0)
  • 2020-12-20 15:27

    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.

    0 讨论(0)
  • 2020-12-20 15:31

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

    0 讨论(0)
提交回复
热议问题