How to use nextPageToken in Google Analytics API using PHP

Advertisement

Have a good day,

I really hope to get the next set of data after getting the first 10,000 Google Analytics data. After further research, there's one thing called nextpagetoken, and I'm embarrassed to get the next set of data. I tried it but I kept getting an error or I did not have any data. Does anyone have the same problem before? Help me with this (code example very appreciated). Thank you very much.

The answer

You must obtain the followingPageToken value from each response and configure all the following requests:

 $client = new \Google_Client(); /* ... */ $analytics = new \Google_Service_AnalyticsReporting($client); $request = new \Google_Service_AnalyticsReporting_ReportRequest(); $request->setViewId($view); $request->setMetrics($metrics); $request->setDateRanges($dateRange); $request->setPageSize(10000); /* ... */ $body = new \Google_Service_AnalyticsReporting_GetReportsRequest(); $body->setReportRequests(array($request)); do { $response = $analytics->reports->batchGet($body, $params); /* ... Processing $response ... */ $request->setPageToken($response[0]->getNextPageToken()); } while ($response[0]->getNextPageToken() != ''); 

Related articles

Google Analytics API: segment for event condition

2014-12-14

I use the Google Spreadsheets Google Analytics plugin. I would segment data to include only visitors who have an event action to "start" against them. Here's what I tried when I try to run the report, Google Sheets says the syntax is invalid: se

The Google Analytics API includes the path

2014-09-29

I'm trying to dynamically set the path in my code using what Google provided: set_include_path(get_include_path() . PATH_SEPARATOR . '/path/to/google-api-php-client/src'); I'm still relatively noob to PHP and I'm going to assume that the /path/to/ mu

Google Analytics Api Error (403) Unconfigured Access

2014-01-05

I'm trying to run the Google Analytics API and started with the basic PHP tutorial from Google. For some reason, I still get the following error message: Error when calling GET https://www.googleapis.com/analytics/v3/management/accounts?key=my_develo

Google Analytics API of localhost

2015-03-05

Work on a php script to extract data from Google Analytics with the Google PHP client API. I installed the script on localhost / ga /. I've installed my API keys, the Google Analytics API enabled. In "Client ID for Web Application": REDIRECT URI

Access specific data from the Google Analytics API

2015-07-18

I'm developing a site where customers allow my app to access the Google Analytics API on their site. I only want limited information from their accounts. Unique Vistits Total visits Is there a way to request access only to this information rather tha