Batch requests with multiple metrics does not work

77 views
Skip to first unread message

Francesco Pepe

unread,
Apr 24, 2017, 1:16:52 PM4/24/17
to AdSense API Forum
I'm trying to make batch requests using multiple metrics as follows:

            $this->client->setUseBatch(true);


            $service = new Google_Service_AdSense($this->client);
            $batch = $service->createBatch();

            $optParams = array(
              'metric' => ['EARNINGS','CLICKS'],
              'dimension' => $dimensions
                     );

                 $req1 = $service->accounts_reports->generate( $accountId, 
                                                          date('Y-m-d', strtotime($widget->settings->date->startDate) ),
                                                          date('Y-m-d', strtotime($widget->settings->date->endDate) ),
                                                          $optParams);

            $req2 = $service->accounts_reports->generate( $accountId, 
                                                          date('Y-m-d', strtotime($compare['startDate']) ),
                                                          date('Y-m-d', strtotime($compare['endDate']) ),
                                                          $optParams);

            $batch->add($req1, "thoreau");
            $batch->add($req2, "shaw");

            $results = $batch->execute();


This requests always return: This is an empty report: no dimensions or metrics were provided.

So it's impossible to make batch requests using multiple metrics?

Dean Lukies (Adsense API Team)

unread,
Apr 24, 2017, 1:20:38 PM4/24/17
to AdSense API Forum
Hi,

I recommend that you do not use the Batch request with the AdSense API.
Although it may work in some instances, it does not work well for reporting.

thanks,
Dean

Francesco Pepe

unread,
Apr 24, 2017, 3:44:25 PM4/24/17
to AdSense API Forum
Hi Dean,

I have tested with javascript client libraries it works well, with php libraries seems buggy.

Can I ask you why it is not recommended?

Dean Lukies (Adsense API Team)

unread,
Apr 24, 2017, 3:50:23 PM4/24/17
to AdSense API Forum
Hi,

Not recommended as it doesn't work with some libraries and it still counts as multiple requests for purposes of quota.

If you want to talk about your particular use case, I would love to hear about it offline, you can write in to adsenseap...@google.com

thanks,
Dean
Reply all
Reply to author
Forward
0 new messages