erebusnz / gapi-google-analytics-php-interface

GA:PI() - Google Analytics PHP Interface
167 stars 86 forks source link

Need to specify separator argument to http_build_query to address problem with & default #118

Closed dawansv closed 9 years ago

dawansv commented 9 years ago

This relates to the use of http_build_query in the curlRequest function (line 757 of gapi.class.php)

In some situations, it seems that the default query separtor on a given server is & instead of &. When http_build_query is called without specifying the separator, the default is used, and if it happens to be & then the request fails.

Simple solution is to specify the separator in the call on line 757 of gapi.class.php: curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_variables, '', '&'));

erebusnz commented 9 years ago

Issue has been fixed in commit ee638cf1e90ecc0bb30bff420f1d2ec096a283da will be released in next version. Thanks

Makcym commented 9 years ago

Hi I did all of the new instruction on different sites with PHP 5.3.3, .p12 file exists but

Fatal error: Uncaught exception 'Exception' with message 'GAPI: Failed load key file "key.p12". Check if correct p12 format.' in YYY.php:603 Stack trace:

0 YYY.php(126): gapiOAuth2->fetchToken('XXX@gmail.com', 'YYY.php', NULL)

1 YYY.php(788): gapi->__construct('XXX@gmail.com', 'YYY.php')

2 {main} thrown in YYY.php on line 603

erebusnz commented 9 years ago

Hi @Makcym,

This issue #118 is relating to a different issue, if you would like to raise this then please create a new issue.

As for your issue, you will need to use a service account, these end in @developer.gserviceaccount.com and need to be created by following these instructions carefully:

GAPI (because now Google Analytics API only supports OAuth2) will require you to create a 'service account' and then download a .P12 file to upload to your application.

  1. Create a Google Developers project
  2. Create service account under this project, see instructions
  3. Download the .p12 file for this service account, upload to the same folder as gapi.class.php
  4. Enable 'analytics API' in the Google Developers console
  5. In Google Analytics Administration > User Management, give the service account 'Read and Analyse' permissions on the analytics accounts you want to access