$user = new AdWordsUser();
$user->LogDefaults();
$reportDefinitionId = (float) '131128463';
$result = ReportUtils::RunAsyncReport($reportDefinitionId,
$queryToken, $user, $options);
This is the old CrossClient type of download.
This code, however:
$user = new AdWordsUser();
$user->LogDefaults();
$reportDefinitionId = '131128463';
ReportUtils::DownloadReport($reportDefinitionId, $path, $user,
$options);
produces:
The client customer ID must be specified for report downloads.
Fair enough, change the above to:
$user = new AdWordsUser();
$user->LogDefaults();
$user->SetClientId('3924112376');
$reportDefinitionId = '131128463';
ReportUtils::DownloadReport($reportDefinitionId, $path, $user,
$options);
produces:
[ReportDefinitionError.INVALID_REPORT_DEFINITION_ID @
selector.selector; errorDetails:reportDefinitionId=ReportDefinitionId:
131128463, customerId=27968988, changeId=0]
which seems very strange to me - the customerId (27968988) not only
doesn't match $user->SetClientId, but it is also only 8 digits, when I
think clientId's are supposed to be at least 9 digits long.
Please let me know what I'm doing wrong here (and also, when you do
set the clientId, how to set it for all of your subaccounts).
How do I download a report that has information for all my clients
with adHoc reports?
Also, through adHoc reports, selector 'Cost' is a microAmount? How
can I change that back to a dollar amount?
Thank you.
Sometimes, the sub=account may have no data returned when generating a
report.
I should just fetch each report anyway? 10 at a time and fetch 300
reports?
(Just making sure.) Thanks.
On Dec 1, 2:03 pm, Eric Koleda <eric.kol...@google.com> wrote:
> Hi,
>
> Cross-client reporting functionality is no longer available in v201109,
> although there are ways to achieve the same results using a series of
> single-client reports:
>
> http://adwordsapi.blogspot.com/2011/10/downloading-reports-for-lots-o...
How do you suggest requesting 10 reports at a time (from an array of
300 customerId's) using php? or is this impossible?
How do you suggest requesting 10 reports at a time (from an array of
300 customerId's) using php? or is this impossible?
I did it with pcntl_fork. (had a lot of different advice on this -
yours turned out to be the best)
The only problem is that it is consistently triggering Captcha's
(except one doing them one at a time, which takes forever). How do I
deal with these?
Here is the code. I will post it in the other discussion groups where
I gave advice pertinent on CrossClient Reports after I complete this
taking care of Captcha's.
<?php
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// AdWordsUser.php directly via require_once.
// $path = '/path/to/aw_api_php_lib/src';
include('../definedb.php'); //
include('./accountsArray.php'); //sets $adwordsAPIpath, uses $selector
= new ServicedAccountSelector(); to make an array of all accounts
//$accountsArray = array('4503399530');
//print_r($accountsArray);exit;
$path = $adwordsAPIpath.'/../../live_api2/src/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'Google/Api/Ads/AdWords/Lib/AdWordsUser.php';
require_once 'Google/Api/Ads/AdWords/Util/ReportUtils.php';
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$user = new AdWordsUser();
//$user->SetClientId($customerId);
// Log SOAP XML request and response.
$user->LogDefaults();
// Load ReportDefinitionService so that the required classes are
available.
$user->LoadService('ReportDefinitionService', 'v201109');
// Create selector.
$selector = new Selector();
$selector->fields = array('ExternalCustomerId',
'AccountDescriptiveName', 'PrimaryUserLogin', 'Date', 'Id', 'Name',
'Impressions', 'Clicks', 'Cost');
//$selector->predicates[] =
//new Predicate('Status', 'IN', array('ENABLED', 'PAUSED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Campaign performance report #' .
time();
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->reportType = 'CAMPAIGN_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
$reportDefinition->includeZeroImpressions = FALSE;
$options = array('version' => 'v201109', 'returnMoneyInMicros' =>
FALSE);
$pids = array();
$j = 0;
for ($i=0; $i<count($accountsArray); $i++) {
if($j==10) { echo $j." ---\n"; $j=0; }
$pids[$i] = pcntl_fork();
if(!$pids[$i]) {
// child process
try {
// Get AdWordsUser from credentials in "../auth.ini"
// relative to the AdWordsUser.php file's directory.
$customerId = $accountsArray[$i];
$user->SetClientId($customerId);
$fileName = "7days-".$customerId.".csv";
$path = dirname(__FILE__) . '/../reports/7days/' . $fileName;
ReportUtils::DownloadReport($reportDefinition, $path, $user,
$options);
printf("Report with name '%s' was downloaded to '%s'.\n",
$reportDefinition->reportName, $fileName);
} catch (Exception $e) {
print $e->getMessage();
}
exit();
}
$j++;
I do this command only once:
$user = new AdWordsUser();
and then I loop through my customerId's like this:
$user->SetClientId($customerId);
I thought only 'new AdWordsUser()' would generate a new AuthToken?
On Dec 16, 3:11 am, "Anash P. Oommen" <anash.p.oommen
> Seehttp://adwordsapi.blogspot.com/2010/07/discover-v2009-working-with-au...for
> more details.
>
> Thanks,
> Anash
changed:
$user = new AdWordsUser();
to:
$user = new AdWordsUser();
$user->GetAuthToken();
and i was able to run it three times without a captcha, so that seemed
to do it... not to mention it runs faster now.
thank you all for your help, Kevin, Anash, Eric
on a side note, debugging was a lot easier with CrossClients. if you
have a single report to download, then you can just check the latest
date in the mysql table you import it into and know that the whole
process went fine.
now you have to check for all of your clients, but if one of the
reports is empty, then it's harder to know if you're missing just a
little bit of the data or there was no data in a report, etc.
On Dec 16, 2:18 pm, Kevin Winter <Kevin.Win...@google.com> wrote:
> Hi,
> In the PHP library, the tokens are generated in a lazy fashion, i.e.
> right before they are needed. If you don't cause the AuthToken to get
> generated BEFORE the fork, then each forked process will generate its own,
> leading to CAPTCHA challenged. You can call GetAuthToken() (http://code.google.com/p/google-api-adwords-php/source/browse/trunk/s...)
Hi Kevin,
can you please tell me how to do this with the ASP.NET library? I
really looked for AuthToken related methods or attributes but didn't
find anything.
Or another way of doing it (which I might even prefer) - is it
possible to login with the MCC account and download the report once
for each Customer without changing the AdwordsUser? Like having a
selector.predicate.field = "CustomerId" or similar?
Best wishes and thanks for any answer
Alexander
Thank you iateadonut. Your solution help us reduce the synchronization time dramatically. From 7~8 hours to within 10 minutes.Best regads,Bill