examples/AdWords/LaravelSampleApp/app/Http/Controllers/AdWordsApiController.php
private function downloadReport(
        $reportType,
        $reportRange,
        ReportDownloader $reportDownloader,
        array $selectedFields
    ) {
        $query = (new ReportQueryBuilder())
            ->select($selectedFields)
            ->from($reportType)
            ->duringDateRange($reportRange)->build();

        // For brevity, this sample app always excludes zero-impression rows.
        $reportSettingsOverride = (new ReportSettingsBuilder())
            ->includeZeroImpressions(false)
            ->build();
        $reportDownloadResult = $reportDownloader->downloadReportWithAwql(
            "$query",
            DownloadFormat::XML,
            $reportSettingsOverride
        );

        $json = json_encode(
            simplexml_load_string($reportDownloadResult->getAsString())
        );
        $resultTable = json_decode($json, true)['table'];

        if (array_key_exists('row', $resultTable)) {
            // When there is only one row, PHP decodes it by automatically
            // removing the containing array. We need to add it back, so the
            // "view" can render this data properly.
            $row = $resultTable['row'];
            $row = count($row) > 1 ? $row : [$row];
            return collect($row);
        }

        // No results returned for this query.
        return collect([]);
    }
private function downloadReport(
        $reportType,
        $reportRange,
        ReportDownloader $reportDownloader,
        array $selectedFields
    ) {
        $query = (new ReportQueryBuilder())
            ->select($selectedFields)
            ->from($reportType)
            ->duringDateRange($reportRange)->build();

        // For brevity, this sample app always excludes zero-impression rows.
        $reportSettingsOverride = (new ReportSettingsBuilder())
            ->includeZeroImpressions(false)
            ->build();
        $reportDownloadResult = $reportDownloader->downloadReportWithAwql(
            "$query",
            DownloadFormat::XML,
            $reportSettingsOverride
        );

        $json = json_encode(
            simplexml_load_string($reportDownloadResult->getAsString())
        );
        $resultTable = json_decode($json, true)['table'];

        if (array_key_exists('row', $resultTable)) {
            // When there is only one row, PHP decodes it by automatically
            // removing the containing array. We need to add it back, so the
            // "view" can render this data properly.
            $row = $resultTable['row'];
            $row = count($row) > 1 ? $row : [$row];
            return collect($row);
        }

        // No results returned for this query.
        return collect([]);
    }
private function downloadReport ( $ reportType , $ reportRange , ReportDownloader $ reportDownloader , array $ selectedFields ) { $ query = ( new ReportQueryBuilder ( ) ) -> select ( $ selectedFields ) -> from ( $ reportType ) -> duringDateRange ( $ reportRange ) -> build ( ) ; // For brevity, this sample app always excludes zero-impression rows. $ reportSettingsOverride = ( new ReportSettingsBuilder ( ) ) -> includeZeroImpressions ( false ) -> build ( ) ; $ reportDownloadResult = $ reportDownloader -> downloadReportWithAwql ( "$query" , DownloadFormat :: XML , $ reportSettingsOverride ) ; $ json = json_encode ( simplexml_load_string ( $ reportDownloadResult -> getAsString ( ) ) ) ; $ resultTable = json_decode ( $ json , true ) [ 'table' ] ; if ( array_key_exists ( 'row' , $ resultTable ) ) { // When there is only one row, PHP decodes it by automatically // removing the containing array. We need to add it back, so the // "view" can render this data properly. $ row = $ resultTable [ 'row' ] ; $ row = count ( $ row ) > 1 ? $ row : [ $ row ] ; return collect ( $ row ) ; } // No results returned for this query. return collect ( [ ] ) ; }
Download a report of the specified report type and date range, selected
fields, and the number of entries per page.

@param string $reportType
@param string $reportRange
@param ReportDownloader $reportDownloader
@param string[] $selectedFields
@return Collection
Download a report of the specified report type and date range selected fields and the number of entries per page .