pownraj-anubavam / google-api-php-client

Automatically exported from code.google.com/p/google-api-php-client
Apache License 2.0
0 stars 0 forks source link

GA :: getting data issue #115

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I don't have any idea about why I see that error. (XXXXXXXX is the id)

<br />
<b>Fatal error</b>:  Uncaught exception 'apiServiceException' with message 
'Error calling GET 
https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3AXXXXXXXX&amp;start-date
=2012-04-03&amp;end-date=2012-04-17&amp;metrics=ga%3Avisitors&amp;dimensions=ga%
3AvisitorType&amp;filters=&amp;segment=gaid%3A%3A-1&amp;sort=&amp;max-results=50
&amp;start-index=&amp;key=73804101181%40developer.gserviceaccount.com: (400) 
Invalid value ''. Values must match the following regular expression: 'ga:.+'' 
in D:\htdocs\src\explorer\src\io\apiREST.php:86
Stack trace:
#0 D:\htdocs\src\explorer\src\io\apiREST.php(56): 
apiREST::decodeHttpResponse(Object(apiHttpRequest))
#1 D:\htdocs\src\explorer\src\service\apiServiceResource.php(187): 
apiREST::execute(Object(apiServiceRequest))
#2 D:\htdocs\src\explorer\src\contrib\apiAnalyticsService.php(244): 
apiServiceResource-&gt;__call('get', Array)
#3 D:\htdocs\src\explorer\explorer.php(119): 
DataGaServiceResource-&gt;get('ga:58425344', '2012-04-03', '2012-04-17', 
'ga:visitors', Array)
#4 D:\htdocs\src\explorer\explorer.php(38): results(Object(apiClient), Obje in 
<b>D:\htdocs\src\explorer\src\io\apiREST.php</b> on line <b>86</b><br />

Original issue reported on code.google.com by seyhunca...@gmail.com on 17 Apr 2012 at 7:11

GoogleCodeExporter commented 9 years ago
OK, I've corrected some lines, but I still see error:

Fatal error: Uncaught exception 'apiException' with message '(get) unknown 
parameter: '1'' in 
D:\htdocs\src\explorer\src\service\apiServiceResource.php:120 Stack trace: #0 
D:\htdocs\src\explorer\src\contrib\apiAnalyticsService.php(244): 
apiServiceResource->__call('get', Array) #1 
D:\htdocs\src\explorer\simple.php(41): 
DataGaServiceResource->get('ga:58425344', '2012-04-03', '2012-04-17', 
'ga:percentNewVi...', Array) #2 {main} thrown in 
D:\htdocs\src\explorer\src\service\apiServiceResource.php on line 120

Original comment by seyhunca...@gmail.com on 17 Apr 2012 at 8:27

GoogleCodeExporter commented 9 years ago
if ($client->getAccessToken()) {

            $optParams = array( 'dimensions' => $_POST['dimensions'],
                                'filters' => $_POST['filters'],
                                'segment' => $_POST['segment'],
                                'sort' => $_POST['sort'],
                                'max-results' => $_POST['max_results'],
                                'start-index' => $_POST['start_index'] ); 

            $data = $service->data_ga->get( $_POST['ids'],
                                            $_POST['start_date'],
                                            $_POST['end_date'],
                                            $_POST['metrics'],
                                            $optParams );

Original comment by seyhunca...@gmail.com on 17 Apr 2012 at 8:32

GoogleCodeExporter commented 9 years ago
is it fixed now?

Original comment by mi...@gravityworksdesign.com on 2 Jul 2012 at 4:10

GoogleCodeExporter commented 9 years ago
Yes, I fixed. Now it works pretty well :)

You can try to catch the error with:

    } else {
      throw new apiServiceException("Error Goes here...");
    }

Also my parameter was wrong. So be careful with ga: and non ga:
Here I share an example

XXXXXXXXX  is my id.

https://www.googleapis.com/analytics/v3/data/ga?ids=ga:XXXXXXXXX&metrics=ga:perc
entNewVisits,ga:newVisits,ga:visitors,ga:visits&start-date=2012-04-03&end-date=2
012-04-17&start-index=1&max-results=1000

Happy Coding.

Original comment by seyhunca...@gmail.com on 3 Jul 2012 at 6:50

GoogleCodeExporter commented 9 years ago
BTW: use urlencode();

Original comment by seyhunca...@gmail.com on 3 Jul 2012 at 7:00

GoogleCodeExporter commented 9 years ago
My API is not ready, because I was busy.
So, I will play these days again with GA.

My idea is, there should be a helper class to check values for validation.
For an example: it's for "start-index" should be with if (is_numeric($start) && 
(int)$start > 1)) else ...//err

I guess, the followed lines can help you.

            $optParams = array( 'dimensions' => 'ga:pageTitle',
                                'filters' => '',
                                //'segment' => '',
                                //'sort' => '-ga:pageviews',
                                'max-results' => '50',
                                'start-index' => '1' ); 

try {

            $data = $service->data_ga->get( 'ga:58425344',
                                            '2012-04-03',
                                            '2012-04-17',
                                            'ga:percentNewVisits,ga:newVisits,ga:visitors,ga:visits',
                                            $optParams );

} catch (apiServiceException $e) {

 if(isset($data)) unset($data);
  $data['text'] = $e->getMessage();  
  $data['error'] = $e->getCode();

}
            print_r($data);

Original comment by seyhunca...@gmail.com on 3 Jul 2012 at 7:49

GoogleCodeExporter commented 9 years ago

Original comment by ianbar...@google.com on 22 Mar 2013 at 2:05

GoogleCodeExporter commented 9 years ago
i m so upset to this error .

Fatal error: Uncaught exception 'Google_ServiceException' with message 'Error 
calling GET 
https://www.googleapis.com/plus/v1/people/me?key=AIzaSyC3rTbC9JeSmk_ysb-IkoBD51Z
c1zA5GV8: (403) Access Not Configured. Please use Google Developers Console to 
activate the API for your project.' in 
C:\xampp\htdocs\googleplus\google-api-php-client\src\io\Google_REST.php:66 
Stack trace: #0 
C:\xampp\htdocs\googleplus\google-api-php-client\src\io\Google_REST.php(36): 
Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 
C:\xampp\htdocs\googleplus\google-api-php-client\src\service\Google_ServiceResou
rce.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 
C:\xampp\htdocs\googleplus\google-api-php-client\src\contrib\Google_PlusService.
php(229): Google_ServiceResource->__call('get', Array) #3 
C:\xampp\htdocs\googleplus\google-plus-access.php(36): 
Google_PeopleServiceResource->get('me') #4 
C:\xampp\htdocs\googleplus\index.php(2): include_once('C:\xampp\htdocs...') #5 
{main} thrown in 
C:\xampp\htdocs\googleplus\google-api-php-client\src\io\Google_REST.php on line 
66

please any one can help me ..

Original comment by asheesh....@gmail.com on 7 Nov 2014 at 12:51