Set budget (not shared) and location (PHP)

97 views
Skip to first unread message

Rick Vugts

unread,
Feb 10, 2014, 7:55:27 PM2/10/14
to adwor...@googlegroups.com
So I created this function to set the location and language, but it doesn't work. I get an error that I get too many loops (seem like a php error). I don't see why it would loop. Even if I don't make it a function (so there is no loop in my script) I still get that error.

function setLocationAndLanguage(AdWordsUser $user, $campaignId,$locationId,$languageId)
{

   // example data
  $locationId = 2036;
  $languageId = 1000;

    $campaignCriterionService =
     $user->GetService('CampaignCriterionService', ADWORDS_VERSION);
    //$campaignCriteria = array();
   
    $location = new Location();
    $location->id = $locationId;
    $campaignCriterion = new CampaignCriterion($campaignId, null, $location);
    $operations[] = new CampaignCriterionOperation($campaignCriterion, 'ADD');
   
    $language = new Language();
    $language->id = $languageId;
    $campaignCriterion = new CampaignCriterion($campaignId, null, $language);
    $operations[] = new CampaignCriterionOperation($campaignCriterion, 'ADD');
   
    // Make the mutate request.
    $result = $campaignCriterionService->mutate($operations);

    // Display results.
    foreach ($result->value as $campaignCriterion) {
        printf("Campaign targeting criterion with ID '%s' and type '%s' was "
            . "added.\n", $campaignCriterion->criterion->id,
            $campaignCriterion->criterion->CriterionType);
  }   
   
}




Second question; How to easily set a budget for a campaign, without creating a shared budget with a label?
I just want to have somtehing like $campaign->budget = 50.00; for example instead of:
 // Create the shared budget (required).
  $budget = new Budget();
  //$budget->name = 'Interplanetary Cruise Budget #' . uniqid();
  $budget->name = $campaignName.' budget';
  $budget->period = 'DAILY';
  $budget->amount = new Money($budget);
  $budget->deliveryMethod = $deliveryMethod;

  $operations = array();

  // Create operation.
  $operation = new BudgetOperation();
  $operation->operand = $budget;
  $operation->operator = 'ADD';
  $operations[] = $operation;



Ray Tsang (AdWords API Team)

unread,
Feb 11, 2014, 4:40:09 PM2/11/14
to adwor...@googlegroups.com
Rick,

Could I trouble you to use the "Reply to Author" function to send me the following:
1. full request/response log/payload with sensitive information removed
2. the PHP error

Thanks,

--
Ray Tsang (AdWords API Advisor)

Mike Young

unread,
Mar 27, 2014, 12:56:51 PM3/27/14
to adwor...@googlegroups.com, rick...@gmail.com
Was there an answer that would set a budget for a single campaign? (if I have budget ID and campaign name in a variable stored already in a DB)

I'm using AWQL method......

Is it as Rick says...something like: -

$mycampaignname= "abctaxis";

$campaign->budget = 50.00;

  $budget = new Budget();
  $budget->name = $mycampaignname.' budget';

Josh Radcliff (AdWords API Team)

unread,
Mar 31, 2014, 11:33:02 AM3/31/14
to adwor...@googlegroups.com, rick...@gmail.com
Hi,

If you have the budget ID then you would want to do something like this:

$mycampaignname= "abctaxis";

$campaign->budget = 50.00; 

  $budget = new Budget();
  $budget->id = ENTER_EXISTING_BUDGET_ID_HERE;
  // NOTE: You only need to specify the values below if you want to change them
  $budget->name = $mycampaignname.' budget';
  $budget->period = 'DAILY';
  $budget->amount = new Money($budget);
  $budget->deliveryMethod = $deliveryMethod;

  $operations = array();

  // Create operation.
  $operation = new BudgetOperation();
  $operation->operand = $budget;
  $operation->operator = 'SET';
  $operations[] = $operation;

  $budgetService = $user->GetService('BudgetService', ADWORDS_VERSION);
  // Make the mutate request.
  $result = $budgetService->mutate($operations);
  $budget = $result->value[0];

The key point is that you need to pass the ID of the existing budget and use a SET operation instead of an ADD operation.

Cheers,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages