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;