Hi guys,

I'm having trouble generating an XML feed using PHP and the Adwords API of 
our MCC clients, their campaigns, and then subsequently each campaign's 
stats. I had this working correctly with v201302, however it appears that 
in the upgrade to v201309, something somewhere has been changed and this 
code no longer works.

At the moment, I'm using the ManagedCustomerService to create the list of 
CustomerId, and then iterating through that list to output the Campaigns 
and using a Criteria Report to grab the stats, the code is below:

$clientService = $user->GetService('ManagedCustomerService', 'v201309');

$selector = new Selector();

// Specify the fields to retrieve.
$selector->fields = array('CustomerId');

$accounts = $clientService->get($selector);

echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<clients>\n";

foreach ($accounts->entries as $key=>$account) {

if (empty($clientId) || (!empty($clientId) && $account->customerId == 
$clientId)) {

echo "\t<client id=\"".$account->customerId."\" 
name=\"".str_replace('&','&amp;',$account->companyName)."\">\n";
echo "\t\t<campaigns>\n";

$user->SetClientId($account->customerId);

$campaignService = $user->GetService('CampaignService', 'v201309');
 $selector = new Selector();
$selector->fields = array('Name');
$selector->paging = new Paging(0, 30);

$page = $campaignService->get($selector);

if(isset($page->entries)){

foreach ($page->entries as $campaign) {

if($campaign->status == 'ACTIVE' && $campaign->budget->period == 'DAILY') {

$campaign->campaignStats = DownloadCriteriaReportExample($user, 
$campaign->id, $startDate, $endDate);

$cost = $campaign->campaignStats->cost->microAmount/1000000;
$clicks = $campaign->campaignStats->conversions;
$impressions = $campaign->campaignStats->impressions;

if(0 < $impressions || '' != $impressions){

echo "\t\t\t<campaign>\n";
echo "\t\t\t\t<id>".$campaign->id."</id>\n";
echo 
"\t\t\t\t<title>".str_replace('&','&amp;',$campaign->name)."</title>\n";
echo "\t\t\t\t<spend>£".$cost."</spend>\n";
echo "\t\t\t\t<convPerClick>".$clicks."</convPerClick>\n";
echo "\t\t\t\t<impressions>".$impressions."</impressions>\n"; 
echo "\t\t\t</campaign>\n";

} 

$res .= ob_get_contents();

ob_flush(); flush(); ob_end_flush();

ob_start();

}

}

}

echo "\t\t</campaigns>\n";
echo "\t</client>\n";

} 

}

echo "</clients>\n";

The above outputs simply:

<clients>
<client id="304XXXXXXX" name="">
<campaigns></campaigns>
</client>
<client id="987XXXXXXX" name="">
<campaigns></campaigns>
</client>
<client id="198XXXXXXX" name="">
<campaigns></campaigns>
</client>
<client id="441XXXXXXX" name="">
<campaigns></campaigns>
</client>
<client id="434XXXXXXX" name="">
<campaigns></campaigns>
</client>
</clients>

So it looks like it's finding the clients, but not the campaigns under each 
client. Could you help diagnose what the issue is here?

Many thanks,

Ryan

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API Forum" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to