P.Shatalov P.Shatalov - 1 year ago 93
PHP Question

Get next report page via Google_Service_AnalyticsReporting_Report

i'm using this library https://github.com/google/google-api-php-client-services and this samples: https://developers.google.com/analytics/devguides/reporting/core/v4/samples?hl=ru

This is a code example:

$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
return $analyticsreporting->reports->batchGet( $body );

The problem is i can't find any methods or example to get the next pages of report.

Answer Source

The Reporting API is different then the other APIs any standard code in the client library that might implement this isn't going to work with it. Due to the fact that the Client library is generated I don't think you are going to find they have created a method specifically for the Reporting API.

I ended up creating something manually for it myself with C#. It will probably not be added to the standard Google .Net client library either because this would be specific to the single API and not Standard.


Basically what I did was copy my request and just change the NextPageToken and send it again. Until NextPageToken returns null.

However, If you are sending more then one report make sure to keep track of each report and its response and the NextPageToken it returns. I am working with the API team to have some kind of report number added to the response so that it can be mapped back properly.


send three reports:

  1. report one contains a NextPageToken.
  2. report two contains a null NextPageToken.
  3. report three contains a NextPageToken.

next call will only be two reports report one and report three. So you code needs to handle the fact that report two is now done. Without actually having any id in the response to tell you that this is report one and three.

Sorry my PHP is to rusty I cant help you implement it in PHP nor do I know of anyone that has done this before.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download