PHP get campaign COST

854 views
Skip to first unread message

testapi...@gmail.com

unread,
Oct 4, 2016, 1:14:44 PM10/4/16
to AdWords API Forum




Hello.
I have a very difficult task for the report adwords campaign. Once a day I through CRON and PHP download the current state of the campaign, more precisely its current cost. I have a test account on ADWORDS.

More specifically I need such code in PHP that will download all the campaigns and their current state of clicks or such which intro id adwords campaign and married her condition.

Just as the picture needs to download the "cost" using PHP. I tried to use the example file a report in code but nothing they did not give me. You can somehow steer me how do I get this expense?

Do you test your account adwords can change the cost for the test?



Shwetha Vastrad (AdWords API Team)

unread,
Oct 4, 2016, 3:56:09 PM10/4/16
to AdWords API Forum
Hi,

You can use the API to download Campaign Performance Report, which includes statistics aggregated at the campaign level. The DownloadCriteriaReport php example demonstrates how to download a Criteria Performance Report. You can use this example as a reference and make necessary changes to download Campaign Performance Report. Since this is a test account, you'll need to set the includeZeroImpressions header to true to include zero impression rows in the report. 

Please note that you'll not be able to download reports at the Manager level using AdWords API. You'll need to make separate report requests for each individual account under your manager account. You can use this example to download reports for all accounts under a manager account. 

Let me know if you have any further questions. 

Regards,
Shwetha, AdWords API Team.

testapi...@gmail.com

unread,
Oct 5, 2016, 6:20:55 AM10/5/16
to AdWords API Forum
In both cases, I have a similar problem:

Downloading reports for 1 managed customers. Report attempt #1 for client customer ID 9102394456 was not downloaded due to: Report download failed. Underlying errors are Type = '', Trigger = '', FieldPath = ''. Report request failed for client customer ID 9102394456. All downloads completed. Results: Successful reports: Failed reports: Client ID 9102394456 => '/tmp/adgroup_2p1gza.csv' End of results.

OR

An error has occurred:162 Report download failed. Underlying errors are Type = '', Trigger = '', FieldPath = ''.

I'm adding to example code line:
  $options['includeZeroImpressions'] = true;

 

Anthony Madrigal

unread,
Oct 5, 2016, 3:02:26 PM10/5/16
to AdWords API Forum
Hello,

Could you please provide me with the report definition or report query you used that resulted in this error? Please do so using reply privately to author.

Thanks,
Anthony
AdWords API Team

testapi...@gmail.com

unread,
Oct 6, 2016, 6:02:08 AM10/6/16
to AdWords API Forum



    try {
            require_once dirname(dirname(__FILE__)) . '/Google/init.php';

  $user = new AdWordsUser();
  $user->LogAll();


  // Get the service, which loads the required classes.
  $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION);

  // Create selector.
  $selector = new Selector();
  $selector->fields = array('Id', 'Name', 'Labels');
  // Labels filtering is performed by ID. You can use containsAny to select
  // campaigns with any of the label IDs, containsAll to select campaigns with
  // all of the label IDs, or containsNone to select campaigns with none of the
  // label IDs.
  $selector->predicates[] = new Predicate('Labels', 'CONTAINS_ANY',
      array($labelId));
  $selector->ordering[] = new OrderBy('Name', 'ASCENDING');

  // Create paging controls.
  $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);

  do {
    // Make the get request.
    $page = $campaignService->get($selector);

    // Display results.
    if (isset($page->entries)) {
      foreach ($page->entries as $campaign) {
        printf("Campaign with name '%s' and ID '%d' and labels '%s'" .
            " was found.\n", $campaign->name, $campaign->id,
            implode(', ',
                array_map(function($label) {
                  return sprintf('%d/%s', $label->id, $label->name);
                }, $campaign->labels)));
      }
    } else {
      print "No campaigns were found.\n";
    }

    // Advance the paging index.
    $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
  } while ($page->totalNumEntries > $selector->paging->startIndex);








    } catch (Exception $e) {
            printf("An error has occurred:".$e->getLine()." %s\n", $e->getMessage() );
// echo '<pre>';
// print_r($return_array);
// echo '</pre>';
//         exit;
        }

testapi...@gmail.com

unread,
Oct 7, 2016, 4:24:42 AM10/7/16
to AdWords API Forum
trying to have a few days to fix it, do you have an idea what to do with it?

Thanet Knack Praneenararat (AdWords API Team)

unread,
Oct 7, 2016, 4:34:04 AM10/7/16
to AdWords API Forum
Hello,

I can't reproduce your errors.
I ran your code and it works fine, fetching all the data.

Are they intermittent errors occurring sometimes? Or do you get these errors all the time?
Besides, what happen if you run our code examples as is?
Do you still get these errors?

Best,
Thanet, AdWords API Team

testapi...@gmail.com

unread,
Oct 7, 2016, 2:18:25 PM10/7/16
to AdWords API Forum
When I'm using this code, all the time I have this error.
 Maby my account have error ? That maby be caused when I use manager test account in google adwords ?
 
Besides, what happen if you run our code examples as is?

Still I have this same error.

Thanet Knack Praneenararat (AdWords API Team)

unread,
Oct 11, 2016, 10:33:42 AM10/11/16
to AdWords API Forum
Hello,

Sorry for late reply.
From what you said, I still don't think it's related to test account or authentication problem.
The trigger, fieldPath, and type are all null, which is strange.

Could you please try running DownloadCriteriaReport and share the result?
In addition, could you tell me your PHP lib version and AdWords API version you use?

Thanks in advance.

Best,
Thanet, AdWords API Team
Reply all
Reply to author
Forward
0 new messages