{"action":"closed","issue":{"url":"https://api.github.com/repos/google/google-api-php-client/issues/877","repository_url":"https://api.github.com/repos/google/google-api-php-client","labels_url":"https://api.github.com/repos/google/google-api-php-client/issues/877/labels{/name}","comments_url":"https://api.github.com/repos/google/google-api-php-client/issues/877/comments","events_url":"https://api.github.com/repos/google/google-api-php-client/issues/877/events","html_url":"https://github.com/google/google-api-php-client/issues/877","id":137305463,"number":877,"title":"Unable to parse the p12 file","user":{"login":"themags-company","id":8804898,"avatar_url":"https://avatars.githubusercontent.com/u/8804898?v=3","gravatar_id":"","url":"https://api.github.com/users/themags-company","html_url":"https://github.com/themags-company","followers_url":"https://api.github.com/users/themags-company/followers","following_url":"https://api.github.com/users/themags-company/following{/other_user}","gists_url":"https://api.github.com/users/themags-company/gists{/gist_id}","starred_url":"https://api.github.com/users/themags-company/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/themags-company/subscriptions","organizations_url":"https://api.github.com/users/themags-company/orgs","repos_url":"https://api.github.com/users/themags-company/repos","events_url":"https://api.github.com/users/themags-company/events{/privacy}","received_events_url":"https://api.github.com/users/themags-company/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-02-29T16:44:20Z","updated_at":"2016-03-02T17:41:05Z","closed_at":"2016-03-02T17:41:05Z","body":"Hi,\r\nI wanted to use your API (https://developers.google.com/analytics/devguides/reporting/core/v3/quickstart/service-php) for a project I am working on in order to connect to the Analytics.\r\nI went step by step:\r\n- Create project\r\n- Enable Analytics API\r\n- Went to Credentials\r\n- Generated an API key - server\r\n- Went to Services (https://console.developers.google.com/permissions/serviceaccounts?project=_)\r\n- Selected my Project\r\n- Created an account and setting up name (checked the option for DwD)\r\n- Saved key P12 in my project & copied the email generated (name themags):\r\n  - themags@astute-harmony-123608.iam.gserviceaccount.com\r\n\r\nThen I downloaded the API (https://github.com/google/google-api-php-client/tree/v1-master) and included it in the project. After that I followed the \"HelloAnalytics.php\" example:\r\n`/ Creates and returns the Analytics service object.\r\n\r\n  // Load the Google API PHP Client Library.\r\n  require_once 'google-api-php-client/src/Google/autoload.php';\r\n\r\n  // Use the developers console and replace the values with your\r\n  // service account email, and relative location of your key file.\r\n  $service_account_email = '<Replace with your service account email address.>';\r\n  $key_file_location = '<Replace with /path/to/generated/client_secrets.p12>';\r\n\r\n  // Create and configure a new client object.\r\n  $client = new Google_Client();\r\n  $client->setApplicationName(\"HelloAnalytics\");\r\n  $analytics = new Google_Service_Analytics($client);\r\n\r\n  // Read the generated client_secrets.p12 key.\r\n  $key = file_get_contents($key_file_location);\r\n  $cred = new Google_Auth_AssertionCredentials(\r\n      $service_account_email,\r\n      array(Google_Service_Analytics::ANALYTICS_READONLY),\r\n      $key\r\n  );\r\n  $client->setAssertionCredentials($cred);`\r\n\r\nUnfortunately I get error from 'Google_Auth_AssertionCredentials'. The error states:\r\n\r\n> Unable to parse the p12 file. Is this a .p12 file? Is the password correct? OpenSSL error: error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag\r\n\r\nI checked:\r\n- p12 key file is accessible and has full rights - read, write everything, i've set it to 777 even\r\n- providing p12 key as string, instead of going through file_get_contents, no change\r\n- I entered (https://console.developers.google.com/permissions/serviceaccounts?project=astute-harmony-123608) and for THEMAGS created a new key, this time downloaded the JSON file\r\n  - I tried including this file\r\n  - Using it as string\r\n  - Tried using this approach I found somewhere in this section\r\n`$client->setAssertionCredentials($client->loadServiceAccountJson(\r\n      Config()->CONFIG_PATH . 'API-Project-4989ab8a90b6.json',\r\n      [Google_Service_Datastore::DATASTORE, Google_Service_Datastore::USERINFO_EMAIL]\r\n))`\r\n\r\nNo change at all. I tried changing the p12 file into .pem:\r\n`openssl pkcs12 -in \"API Project-39255d2f4c4a.p12\" -out \"api_key.pem\"`\r\nI get the following errors:\r\n\r\n> 9364:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:.\\crypto\\asn1\\tasn_dec.c:1196:\r\n> 9364:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:.\\crypto\\asn1\\tasn_dec.c:370:Type=PKCS12\r\n\r\nI've tried setting up a key on the default email: 440123294185-compute​@developer.gservicea​ccount.com and went through all of these steps again, but still the same.\r\n\r\nI've tried also to read the certificate manually without going through the API, so I just set:\r\n`openssl_pkcs12_read($key, $dummy, 'notasecret')`\r\nWhere $key carried the value of the certificate - both approaches file_get_contents && string tested. I received same error as listed before.\r\n\r\nBoth:\r\n440123294185-compute​@developer.gservicea​ccount.com\r\nand \r\nthemags@astute-harmony-123608.iam.gserviceaccount.com\r\nare set in the Analytics account and have access, but I don't think the problem is there.\r\n\r\nThere is something wrong with the certificate File I am downloading, but I can't understand what...\r\n\r\n\r\nI've read and tested quite a lot of scenarios, but nothing seems to work.\r\n\r\n\r\nPlease advice! Am I missing something or doing something wrong?\r\n\r\n\r\nWill be waiting for your reply.\r\n\r\nKind regards,\r\nSvetoslav Dragoev"}}