I'm have just installed Google API on my server. The aim is to get daily expense of the account. I was playing around with 'GetCampaigns.php' example, which use 'CampaignService' service. This service has different fields such as Id, Name, Amount and many others. I want the code below to grab all campaigns and print their name and amount spent.
<?php
require_once dirname(dirname(__FILE__)) . '/init.php';
function GetCampaignsExample(AdWordsUser $user) {
$campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);
$selector = new Selector();
$selector->fields = array('Name', 'Amount');
$selector->ordering[] = new OrderBy('Name', 'ASCENDING');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
do {
$page = $campaignService->get($selector);
if (isset($page->entries)) {
foreach ($page->entries as $campaign) {
printf("Campaign with name '%s' with amount '%s' was found.\n",
$campaign->name, $campaign->amount);
}
} else {
print "No campaigns were found.\n";
}
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
}
if (__FILE__ != realpath($_SERVER['PHP_SELF'])) {
// return;
}
try {
$user = new AdWordsUser();
$user->LogAll();
GetCampaignsExample($user);
} catch (Exception $e) {
printf("An error has occurred: %s\n", $e->getMessage());
}
?>
However, I don't understand a reason why the page outputs:
Notice: Undefined property: Campaign::$amount in /public_html/adwords/examples/AdWords/v201409/BasicOperations/GetCampaigns.php on line 17 Campaign with name 'My Campaign' and amount '' was found.
The name is successfully retrieved but the amount is not.
May be somebody has a complete solution to get total budget spent for a date range?
Thank you