Hi there,
I am using the php google api client lib 2.7, and the code is from one of the example to get a report file.
Te code is as following:
<?php
/*
* BEFORE RUNNING:
* ---------------
* 1. If not already done, enable the DCM/DFA Reporting And Trafficking API
* and check the quota for your project at
* https://console.developers.google.com/apis/api/dfareporting
* 2. Install the PHP client library with Composer. Check installation
* instructions at https://github.com/google/google-api-php-client.
*/
// Autoload Composer.
require_once(dirname(__FILE__) . '/../../../../API/google-api-php-client/vendor/autoload.php');
$client = getClient();
$service = new Google_Service_Dfareporting($client);
// The DFA profile ID.
$profileId = 'XXXXXXX';// TODO: Update placeholder value.
// The ID of the report.
$reportId = '86233009';// TODO: Update placeholder value.
// The ID of the report file.
$fileId = '550797965';// TODO: Update placeholder value.
$optParams = [];
// TODO: To download media content, use:
//
//$optParams['alt'] = 'media';
$response = $service->reports_files->get($profileId, $reportId, $fileId, $optParams);
// TODO: Change code below to process the `response` object:
echo var_export($response, true), "\n";I got a good response:
Google_Service_Dfareporting_DfareportingFile::__set_state(array(
'dateRangeType' => 'Google_Service_Dfareporting_DateRange',
'dateRangeDataType' => '',
'etag' => '"zf-Ex2azBQPoRFyAodl9rnA6vZY/MTQ5MjcyNzE2NjAwMA"',
'fileName' => 'mozilla_basic_last_30_days',
'format' => 'CSV',
'id' => '550797965',
'kind' => 'dfareporting#file',
'lastModifiedTime' => '1492727166000',
'reportId' => '86233009',
'status' => 'REPORT_AVAILABLE',
'urlsType' => 'Google_Service_Dfareporting_DfareportingFileUrls',
'urlsDataType' => '',
'internal_gapi_mappings' =>
array (
),
'modelData' =>
array (
'dateRange' =>
array (
'kind' => 'dfareporting#dateRange',
'startDate' => '2017-03-21',
'endDate' => '2017-04-19',
),
'urls' =>
array (
'browserUrl' => '
https://www.google.com/analytics/dfa/downloadFile?id=86233009:550797965',
'apiUrl' => '
https://www.googleapis.com/dfareporting/v2.7/reports/86233009/files/550797965?alt=media',
),
),
'processed' =>
array (
),
))
Then I changed to
$optParams['alt'] = 'media'; and reran, then I got the error:
PHP Fatal error: Uncaught exception 'Google_Service_Exception' with message '<?xml version='1.0' encoding='UTF-8'?><Error><Code>SignatureDoesNotMatch</Code><Message>The request signature we calculated does not match the signature you provided. Check your Google secret key and signing method.</Message><StringToSign>GET
application/json
1492743338
/dfa_-18addc8bc9528485b7ceca4319be6264fb19b78d/258203_test_basic_last_30_days_20170420_232557_550797965.csv</StringToSign></Error>' in /opt/fetch/API/google-api-php-client/vendor/google/apiclient/src/Google/Http/REST.php:118
Stack trace:
#0 /opt/fetch/API/google-api-php-client/vendor/google/apiclient/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), NULL)
#1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), NULL)
#2 /opt/fetch/API/google-api-php-client/vendor/google/apiclient/src/Google/Task/Runner.php(176): call_user_func_array(Array, Arra in /opt/fetch/API/google-api-php-client/vendor/google/apiclient/src/Google/Http/REST.php on line 118I also built this simple test will the Java libraries, I also got an error with much less info:
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
Forbidden
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:146)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeMedia(AbstractGoogleClientRequest.java:380)
at com.google.api.services.dfareporting.Dfareporting$Files$Get.executeMedia(Dfareporting.java:14011)
at com.searchrev.pconnect.google.dfa.reporting.DownloadReportFile.downloadFileId(DownloadReportFile.java:46)
at CLIAccessor.saveFile(CLIAccessor.java:727)
at CLIAccessor.handleDownloadFile(CLIAccessor.java:593)
at CLIAccessor.main(CLIAccessor.java:111)
Any help to point me to the right direction to figure out the cause and the fix of this error will be greatly appreciated.
Thanks!!
Fred