/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the ad group to update */ function UpdateAdGroupExample(\AdWords\User $user, $adGroupId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\AdGroupService $adGroupService */ $adGroupService = $soapClientFactory->generateSoapClient('AdGroup'); // Create ad group using an existing ID. $adGroup = new \AdWords\cm\v201109\AdGroup(); $adGroup->id = $adGroupId; // Update the bid. $adGroup->bids = new \AdWords\cm\v201109\ManualCPCAdGroupBids(); $adGroup->bids->keywordMaxCpc = new \AdWords\cm\v201109\Bid(); $adGroup->bids->keywordMaxCpc->amount = new \AdWords\cm\v201109\Money(); $adGroup->bids->keywordMaxCpc->amount->microAmount = 0.75 * 1000000.0; // Create operation. $operation = new \AdWords\cm\v201109\AdGroupOperation(); $operation->operand = $adGroup; $operation->operator = 'SET'; $operations = array($operation); // Make the mutate request. $result = $adGroupService->mutate($operations); // Display result. $adGroup = $result->value[0]; printf("Ad group with id '%s' has updated default bid '\$%s'.\n", $adGroup->id, $adGroup->bids->keywordMaxCpc->amount->microAmount / 1000000.0); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the ad group that the keyword is in * @param string $criterionId the id of the keyword to delete */ function DeleteKeywordExample(\AdWords\User $user, $adGroupId, $criterionId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupService $adGroupCriterionService */ $adGroupCriterionService = $soapClientFactory->generateSoapClient('AdGroupCriterion'); // Create base class criterion to avoid setting keyword and placement specific // fields. $criterion = new \AdWords\cm\v201109\Criterion(); $criterion->id = $criterionId; // Create ad group criterion. $adGroupCriterion = new \AdWords\cm\v201109\AdGroupCriterion(); $adGroupCriterion->adGroupId = $adGroupId; $adGroupCriterion->criterion = new \AdWords\cm\v201109\Criterion($criterionId); // Create operation. $operation = new \AdWords\cm\v201109\AdGroupCriterionOperation(); $operation->operand = $adGroupCriterion; $operation->operator = 'REMOVE'; $operations = array($operation); // Make the mutate request. $result = $adGroupCriterionService->mutate($operations); // Display result. $adGroupCriterion = $result->value[0]; printf("Keyword with id '%s' was deleted.\n", $adGroupCriterion->criterion->id); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the ad group the ad is in * @param string $adId the id of the ad */ function deleteAdExample(\AdWords\User $user, $adGroupId, $adId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupService $adGroupAdService */ $adGroupAdService = $soapClientFactory->generateSoapClient('AdGroupAd'); // Create base class ad to avoid setting type specific fields. $ad = new \AdWords\cm\v201109\Ad(); $ad->id = $adId; // Create ad group ad. $adGroupAd = new \AdWords\cm\v201109\AdGroupAd(); $adGroupAd->adGroupId = $adGroupId; $adGroupAd->ad = $ad; // Create operation. $operation = new \AdWords\cm\v201109\AdGroupAdOperation(); $operation->operand = $adGroupAd; $operation->operator = 'REMOVE'; $operations = array($operation); // Make the mutate request. $result = $adGroupAdService->mutate($operations); // Display result. $adGroupAd = $result->value[0]; printf("Ad with id '%s' was deleted.\n", $adGroupAd->ad->id); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $campaignId the ID of the campaign to update */ function updateCampaignExample(\AdWords\User $user, $campaignId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\CampaignService $campaignService */ $campaignService = $soapClientFactory->generateSoapClient('Campaign'); // Create campaign using an existing ID. $campaign = new \AdWords\cm\v201109\Campaign(); $campaign->id = $campaignId; // Updated the budget delivery method. $campaign->budget = new \AdWords\cm\v201109\Budget(); $campaign->budget->deliveryMethod = 'ACCELERATED'; // Create operation. $operation = new \AdWords\cm\v201109\CampaignOperation(); $operation->operand = $campaign; $operation->operator = 'SET'; $operations = array($operation); // Make the mutate request. $result = $campaignService->mutate($operations); // Display result. $campaign = $result->value[0]; printf("Campaign with id '%s' has updated budget delivery method '%s'.\n", $campaign->id, $campaign->budget->deliveryMethod); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with */ function GetCampaignsExample(\AdWords\User $user) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\CampaignService $campaignService */ $campaignService = $soapClientFactory->generateSoapClient('Campaign'); // $campaignService->setRequestObserver('print_r'); // Create selector. $selector = new \AdWords\cm\v201109\Selector(array('Id', 'Name'), null, null, new \AdWords\cm\v201109\OrderBy('Name', 'ASCENDING'), new \AdWords\cm\v201109\Paging(0, 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 '%s' was found.\n", $campaign->name, $campaign->id); } } else { print "No campaigns were found.\n"; } // Advance the paging index. $selector->paging->startIndex += PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with */ function lookupLocationExample(\AdWords\User $user) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\LocationCriterionService $locationCriterionService */ $locationCriterionService = $soapClientFactory->generateSoapClient('LocationCriterion'); // Location names to look up. $locationNames = array('Paris', 'Quebec', 'Spain', 'Deutschland'); // Locale to retrieve location names in. $locale = 'en'; $selector = new \AdWords\cm\v201109\Selector(); $selector->fields = array('Id', 'LocationName', 'CanonicalName', 'DisplayType', 'ParentLocations', 'Reach'); // Location names must match exactly, only EQUALS and IN are supported. $selector->predicates[] = new \AdWords\cm\v201109\Predicate('LocationName', 'IN', $locationNames); // Only one locale can be used in a request. $selector->predicates[] = new \AdWords\cm\v201109\Predicate('Locale', 'EQUALS', $locale); // Make the get request. $locationCriteria = $locationCriterionService->get($selector); // Display results. if (isset($locationCriteria)) { foreach ($locationCriteria as $locationCriterion) { /** @var \AdWords\cm\v201109\LocationCriterion $locationCriterion */ if (isset($locationCriterion->location->parentLocations)) { $parentLocations = implode(', ', array_map('getLocationString', (array) $locationCriterion->location->parentLocations)); } else { $parentLocations = 'N/A'; } printf("The search term '%s' returned the location '%s' of type '%s' " . "with ID '%s', parent locations '%s', and reach '%d'.\n", $locationCriterion->searchTerm, $locationCriterion->location->locationName, $locationCriterion->location->displayType, $locationCriterion->location->id, $parentLocations, $locationCriterion->reach); } } else { print "No location criteria were found.\n"; } }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the parent ad group */ function GetKeywordsExample(\AdWords\User $user, $adGroupId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupService $adGroupCriterionService */ $adGroupCriterionService = $soapClientFactory->generateSoapClient('AdGroupCriterion'); // Create selector. $selector = new \AdWords\cm\v201109\Selector(); $selector->fields = array('KeywordText', 'KeywordMatchType', 'Id'); $selector->ordering[] = new \AdWords\cm\v201109\OrderBy('KeywordText', 'ASCENDING'); // Create predicates. $selector->predicates[] = new \AdWords\cm\v201109\Predicate('AdGroupId', 'IN', array($adGroupId)); $selector->predicates[] = new \AdWords\cm\v201109\Predicate('CriteriaType', 'IN', array('KEYWORD')); // Create paging controls. $selector->paging = new \AdWords\cm\v201109\Paging(0, PAGE_SIZE); do { // Make the get request. $page = $adGroupCriterionService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $adGroupCriterion) { printf("Keyword with text '%s', match type '%s', and id '%s' was found.\n", $adGroupCriterion->criterion->text, $adGroupCriterion->criterion->matchType, $adGroupCriterion->criterion->id); } } else { print "No keywords were found.\n"; } // Advance the paging index. $selector->paging->startIndex += PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the ad group that contains the keyword * @param string $criterionId the id of the keyword */ function updateKeywordExample(\AdWords\User $user, $adGroupId, $criterionId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupService $adGroupCriterionService */ $adGroupCriterionService = $soapClientFactory->generateSoapClient('AdGroupCriterion'); // Create criterion using an existing ID. Use the base class Criterion // instead of Keyword to avoid having to set ad-specific fields. $criterion = new \AdWords\cm\v201109\Criterion(); $criterion->id = $criterionId; // Create ad group criterion. $adGroupCriterion = new \AdWords\cm\v201109\BiddableAdGroupCriterion(); $adGroupCriterion->adGroupId = $adGroupId; $adGroupCriterion->criterion = new \AdWords\cm\v201109\Criterion($criterionId); // Update destination URL. $adGroupCriterion->destinationUrl = 'http://www.example.com'; // Create operation. $operation = new \AdWords\cm\v201109\AdGroupCriterionOperation(); $operation->operand = $adGroupCriterion; $operation->operator = 'SET'; $operations = array($operation); print_r($operations); // Make the mutate request. $result = $adGroupCriterionService->mutate($operations); // Display result. $adGroupCriterion = $result->value[0]; printf("Keyword with id '%s' has updated destination URL '%s'.\n", $adGroupCriterion->criterion->id, $adGroupCriterion->destinationUrl); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the ID of the ad group to add the keywords to */ function addKeywordsExample(\AdWords\User $user, $adGroupId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupService $adGroupCriterionService */ $adGroupCriterionService = $soapClientFactory->generateSoapClient('AdGroupCriterion'); // Create keyword criteria. $criteria = array(); for ($i = 0; $i < NUM_KEYWORDS; $i++) { $keyword = new \AdWords\cm\v201109\Keyword(); $keyword->text = 'mars cruise ' . uniqid(); $keyword->matchType = 'BROAD'; $criteria[] = $keyword; } // Create ad group criteria and operations. $operations = array(); foreach ($criteria as $criterion) { $adGroupCriterion = new \AdWords\cm\v201109\BiddableAdGroupCriterion(); $adGroupCriterion->adGroupId = $adGroupId; $adGroupCriterion->criterion = $criterion; $operation = new \AdWords\cm\v201109\AdGroupCriterionOperation(); $operation->operand = $adGroupCriterion; $operation->operator = 'ADD'; $operations[] = $operation; } // Make the mutate request. $result = $adGroupCriterionService->mutate($operations); // Display results. foreach ($result->value as $adGroupCriterion) { printf("Keyword with text '%s', match type '%s', and id '%s' was added.\n", $adGroupCriterion->criterion->text, $adGroupCriterion->criterion->matchType, $adGroupCriterion->criterion->id); } }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $campaignId the ID of the campaign to add the ad group to */ function addAdGroupExample(\AdWords\User $user, $campaignId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\AdGroupService $adGroupService */ $adGroupService = $soapClientFactory->generateSoapClient('AdGroup'); // Create ad group. $adGroup = new \AdWords\cm\v201109\AdGroup(); $adGroup->name = 'Earth to Mars Cruise #' . uniqid(); $adGroup->status = 'ENABLED'; $adGroup->campaignId = $campaignId; // Create ad group bid. $adGroupBids = new \AdWords\cm\v201109\ManualCPCAdGroupBids(); $bid = new \AdWords\cm\v201109\Bid(); $bid->amount = new \AdWords\cm\v201109\Money(); $bid->amount->microAmount = 1000000.0; $adGroupBids->keywordMaxCpc = $bid; $adGroup->bids = $adGroupBids; // Create operation. $operation = new \AdWords\cm\v201109\AdGroupOperation(); $operation->operand = $adGroup; $operation->operator = 'ADD'; $operations = array($operation); // Make the mutate request. $result = $adGroupService->mutate($operations); // Display result. $adGroup = $result->value[0]; printf("Ad group with name '%s' and id '%s' was added.\n", $adGroup->name, $adGroup->id); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the ad group to delete */ function deleteAdGroupExample(\AdWords\User $user, $adGroupId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\AdGroupService $adGroupService */ $adGroupService = $soapClientFactory->generateSoapClient('AdGroup'); // Create ad group with DELETED status. $adGroup = new \AdWords\cm\v201109\AdGroup(); $adGroup->id = $adGroupId; $adGroup->status = 'DELETED'; // Rename the ad group as you delete it, to avoid future name conflicts. $adGroup->name = 'Deleted ' . date('Ymd his'); // Create operations. $operation = new \AdWords\cm\v201109\AdGroupOperation(); $operation->operand = $adGroup; $operation->operator = 'SET'; $operations = array($operation); // Make the mutate request. $result = $adGroupService->mutate($operations); // Display result. $adGroup = $result->value[0]; printf("Ad group with id '%s' was deleted.\n", $adGroup->id); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the ad group containing the ad * @param string $adId the ID of the ad */ function pauseAdExample(\AdWords\User $user, $adGroupId, $adId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupService $adGroupAdService */ $adGroupAdService = $soapClientFactory->generateSoapClient('AdGroupAd'); // Create ad using an existing ID. Use the base class Ad instead of TextAd to // avoid having to set ad-specific fields. $ad = new \AdWords\cm\v201109\Ad(); $ad->id = $adId; // Create ad group ad. $adGroupAd = new \AdWords\cm\v201109\AdGroupAd(); $adGroupAd->adGroupId = $adGroupId; $adGroupAd->ad = $ad; // Update the status. $adGroupAd->status = 'PAUSED'; // Create operation. $operation = new \AdWords\cm\v201109\AdGroupAdOperation(); $operation->operand = $adGroupAd; $operation->operator = 'SET'; $operations = array($operation); // Make the mutate request. $result = $adGroupAdService->mutate($operations); // Display result. $adGroupAd = $result->value[0]; printf("Ad of type '%s' with id '%s' has updated status '%s'.\n", $adGroupAd->ad->AdType, $adGroupAd->ad->id, $adGroupAd->status); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the parent ad group */ function getTextAdsExample(\AdWords\User $user, $adGroupId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupAdService $adGroupAdService */ $adGroupAdService = $soapClientFactory->generateSoapClient('AdGroupAd'); // Create selector. $selector = new \AdWords\cm\v201109\Selector(); $selector->fields = array('Headline', 'Id'); $ordering = new \AdWords\cm\v201109\OrderBy(); $ordering->field = 'Headline'; $ordering->sortOrder = 'ASCENDING'; $selector->ordering[] = $ordering; // Create predicates. $predicate1 = new \AdWords\cm\v201109\Predicate(); $predicate1->field = 'AdGroupId'; $predicate1->operator = 'IN'; $predicate1->values = array($adGroupId); $predicate2 = new \AdWords\cm\v201109\Predicate(); $predicate2->field = 'AdType'; $predicate2->operator = 'IN'; $predicate2->values = array('TEXT_AD'); // By default disabled ads aren't returned by the selector. To return them // include the DISABLED status in a predicate. $predicate3 = new \AdWords\cm\v201109\Predicate(); $predicate3->field = 'Status'; $predicate3->operator = 'IN'; $predicate3->values = array('ENABLED', 'PAUSED', 'DISABLED'); $selector->predicates[] = $predicate1; $selector->predicates[] = $predicate2; $selector->predicates[] = $predicate3; // Create paging controls. $selector->paging = new \AdWords\cm\v201109\Paging(); $selector->paging->numberResults = PAGE_SIZE; $selector->paging->startIndex = 0; do { // Make the get request. $page = $adGroupAdService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $adGroupAd) { printf("Text ad with headline '%s' and id '%s' was found.\n", $adGroupAd->ad->headline, $adGroupAd->ad->id); } } else { print "No text ads were found.\n"; } // Advance the paging index. $selector->paging->startIndex += PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with */ function getAccountHierarchyExample(\AdWords\User $user) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\mcm\v201109\ServicedAccountService $servicedAccountService */ $servicedAccountService = $soapClientFactory->generateSoapClient('ServicedAccount'); // Create selector. $selector = new \AdWords\mcm\v201109\ServicedAccountSelector(); // To get the links paging must be disabled. $selector->enablePaging = false; // Make the get request. $graph = $servicedAccountService->get($selector); // Display serviced account graph. if (isset($graph->accounts)) { // Create map from customerId to parent and child links. $childLinks = array(); $parentLinks = array(); if (isset($graph->links)) { foreach ($graph->links as $link) { $childLinks[$link->managerId->id][] = $link; $parentLinks[$link->clientId->id][] = $link; } } // Create map from customerID to account, and find root account. $accounts = array(); $rootAccount = null; foreach ($graph->accounts as $account) { $accounts[(string) $account->customerId] = $account; if (!array_key_exists((string) $account->customerId, $parentLinks)) { $rootAccount = $account; } } // The root account may not be returned in the sandbox. if (!isset($rootAccount)) { $rootAccount = new \AdWords\mcm\v201109\Account(); $rootAccount->customerId = 0; $rootAccount->login = $user->GetEmail(); } // Display account tree. print "(Customer Id, Account Name/Login, Link Status)\n"; displayAccountTree($rootAccount, NULL, $accounts, $childLinks, 0); } else { print "No serviced accounts were found.\n"; } }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $campaignId the id of the parent campaign */ function getAdGroupsExample(\AdWords\User $user, $campaignId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\AdGroupService $adGroupService */ $adGroupService = $soapClientFactory->generateSoapClient('AdGroup'); // Create selector. $selector = new \AdWords\cm\v201109\Selector(); $selector->fields = array('Id', 'Name'); $orderBy = new \AdWords\cm\v201109\OrderBy(); $orderBy->field = 'Name'; $orderBy->sortOrder = 'ASCENDING'; $selector->ordering[] = $orderBy; // Create predicates. $predicate = new \AdWords\cm\v201109\Predicate(); $predicate->field = 'CampaignId'; $predicate->operator = 'IN'; $predicate->values = array($campaignId); $selector->predicates[] = $predicate; // Create paging controls. $selector->paging = new \AdWords\cm\v201109\Paging(); $selector->paging->startIndex = 0; $selector->paging->numberResults = PAGE_SIZE; do { // Make the get request. $page = $adGroupService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $adGroup) { printf("Ad group with name '%s' and id '%s' was found.\n", $adGroup->name, $adGroup->id); } } else { print "No ad groups were found.\n"; } // Advance the paging index. $selector->paging->startIndex += PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with */ function addCampaignExample(\AdWords\User $user) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); // Get the service, which loads the required classes. /** @var \AdWords\cm\v201109\CampaignService $campaignService */ $campaignService = $soapClientFactory->generateSoapClient('Campaign'); // Create campaign. $campaign = new \AdWords\cm\v201109\Campaign(); $campaign->name = 'Interplanetary Cruise #' . uniqid(); $campaign->status = 'PAUSED'; $campaign->biddingStrategy = new \AdWords\cm\v201109\ManualCPC(); $budget = new \AdWords\cm\v201109\Budget(); $budget->period = 'DAILY'; $budget->amount = new \AdWords\cm\v201109\Money(); $budget->amount->microAmount = 50000000.0; $budget->deliveryMethod = 'STANDARD'; $campaign->budget = $budget; // Set the campaign network options to Google Search and Search Network. $networkSetting = new \AdWords\cm\v201109\NetworkSetting(); $networkSetting->targetGoogleSearch = true; $networkSetting->targetSearchNetwork = true; $networkSetting->targetContentNetwork = false; $networkSetting->targetContentContextual = false; $networkSetting->targetPartnerSearchNetwork = false; $campaign->networkSetting = $networkSetting; // Create operation. $operation = new \AdWords\cm\v201109\CampaignOperation(); $operation->operand = $campaign; $operation->operator = 'ADD'; $operations = array($operation); // Make the mutate request. $result = $campaignService->mutate($operations); // Display result. $campaign = $result->value[0]; printf("Campaign with name '%s' and id '%s' was added.\n", $campaign->name, $campaign->id); }
/** * Runs the example. * * @param \AdWords\User $user the user to run the example with * @param string $adGroupId the id of the ad group to add the ads to */ function addTextAdsExample(\AdWords\User $user, $adGroupId) { $soapClientFactory = new \AdWords\SoapClientFactory($user, null, false); // Sandbox server $soapClientFactory->setServer('https://adwords-sandbox.google.com'); /** @var \AdWords\cm\v201109\AdGroupService $adGroupAdService */ $adGroupAdService = $soapClientFactory->generateSoapClient('AdGroupAd'); // Create text ads. $ads = array(); for ($i = 0; $i < NUM_ADS; $i++) { $textAd = new \AdWords\cm\v201109\TextAd(); $textAd->headline = 'Cruise #' . uniqid(); $textAd->description1 = 'Visit the Red Planet in style.'; $textAd->description2 = 'Low-gravity fun for everyone!'; $textAd->displayUrl = 'www.example.com'; $textAd->url = 'http://www.example.com'; $ads[] = $textAd; } // Create ad group ads and operations. $operations = array(); foreach ($ads as $ad) { $adGroupAd = new \AdWords\cm\v201109\AdGroupAd(); $adGroupAd->adGroupId = $adGroupId; $adGroupAd->ad = $ad; // Create operation. $operation = new \AdWords\cm\v201109\AdGroupAdOperation(); $operation->operand = $adGroupAd; $operation->operator = 'ADD'; $operations[] = $operation; } // Make the mutate request. $result = $adGroupAdService->mutate($operations); // Display results. foreach ($result->value as $adGroupAd) { printf("Text ad with headline '%s' and id '%s' was added.\n", $adGroupAd->ad->headline, $adGroupAd->ad->id); } }