Google API - get daily spent with PHP - Problem

45 views
Skip to first unread message

al...@myticketsonline.eu

unread,
Feb 18, 2015, 7:55:03 AM2/18/15
to adwor...@googlegroups.com

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

Danial Klimkin

unread,
Feb 18, 2015, 8:15:20 AM2/18/15
to adwor...@googlegroups.com
Hello,


Stats (including Cost) are not available via the services. Please use the reporting instead:



-Danial, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages