Gets the service by its service name and group.
public GetService ( string $serviceName, string | null $version = null, string | null $server = null, SoapClientFactory $serviceFactory = null, boolean | null $validateOnly = null, boolean | null $partialFailure = null ) : SoapClient | ||
$serviceName | string | the service name |
$version | string | null | the version of the service to get. If null, then the default version will be used |
$server | string | null | the server to make the request to. If null, then the default server will be used |
$serviceFactory | SoapClientFactory | the factory to create the client. If null, then the built-in SOAP client factory will be used |
$validateOnly | boolean | null | if the service should be created in validateOnly mode |
$partialFailure | boolean | null | if the service should be created in partialFailure mode |
Résultat | SoapClient | the instantiated service |
function AddTextAdsExample(AdWordsUser $user, $adGroupId) { // Get the service, which loads the required classes. $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION); $numAds = 5; $operations = array(); for ($i = 0; $i < $numAds; $i++) { // Create text ad. $textAd = new 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->finalUrls = array('http://www.example.com'); // Create ad group ad. $adGroupAd = new AdGroupAd(); $adGroupAd->adGroupId = $adGroupId; $adGroupAd->ad = $textAd; // Set additional settings (optional). $adGroupAd->status = 'PAUSED'; // Create operation. $operation = new 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); } }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the ID of the campaign to add the sitelinks to */ function UploadOfflineConversionsExample(AdWordsUser $user, $conversionName, $gClId, $conversionTime, $conversionValue) { // Get the services, which loads the required classes. $conversionTrackerService = $user->GetService('ConversionTrackerService', ADWORDS_VERSION); $offlineConversionService = $user->GetService('OfflineConversionFeedService', ADWORDS_VERSION); // Create an upload conversion. Once created, this entry will be visible // under Tools and Analysis->Conversion and will have Source = "Import". $uploadConversion = new UploadConversion(); $uploadConversion->category = 'PAGE_VIEW'; $uploadConversion->name = $conversionName; $uploadConversion->viewthroughLookbackWindow = 30; $uploadConversion->ctcLookbackWindow = 90; $uploadConversionOperation = new ConversionTrackerOperation(); $uploadConversionOperation->operator = 'ADD'; $uploadConversionOperation->operand = $uploadConversion; $uploadConversionOperations = array($uploadConversionOperation); $result = $conversionTrackerService->mutate($uploadConversionOperations); $uploadConversion = $result->value[0]; printf("New upload conversion type with name = '%s' and ID = %d was " . "created.\n", $uploadConversion->name, $uploadConversion->id); // Associate offline conversions with the upload conversion we created. $feed = new OfflineConversionFeed(); $feed->conversionName = $conversionName; $feed->conversionTime = $conversionTime; $feed->conversionValue = $conversionValue; $feed->googleClickId = $gClId; $offlineConversionOperation = new OfflineConversionFeedOperation(); $offlineConversionOperation->operator = 'ADD'; $offlineConversionOperation->operand = $feed; $offlineConversionOperations = array($offlineConversionOperation); $result = $offlineConversionService->mutate($offlineConversionOperations); $feed = $result->value[0]; printf('Uploaded offline conversion value of %d for Google Click ID = ' . "'%s' to '%s'.", $feed->conversionValue, $feed->googleClickId, $feed->conversionName); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function AddPromotionExample(AdWordsUser $user, $businessId) { // Get the business service, which loads the required classes. $businessService = $user->GetService('ExpressBusinessService', ADWORDS_VERSION); // Get the business for the businessId. We will need its geo point // to create a Proximity criterion for the new Promotion. $businessSelector = new Selector(); $businessSelector->fields = array('Id', 'GeoPoint'); $businessPredicate = new Predicate('Id', 'EQUALS', array($businessId)); $businessSelector->predicates = array($businessPredicate); $businessEntries = $businessService->get($businessSelector)->entries; $business = $businessEntries[0]; // PromotionService requires the businessId on the user. $user->SetExpressBusinessId($businessId); // Get the promotion service. $promotionService = $user->GetService('PromotionService', ADWORDS_VERSION); // Set up the new Promotion. $marsTourPromotion = new Promotion(); $budget = new Money(); $budget->microAmount = 1000000; $marsTourPromotion->name = 'Mars Tour Promotion ' . uniqid(); $marsTourPromotion->status = 'PAUSED'; $marsTourPromotion->destinationUrl = 'http://www.example.com'; $marsTourPromotion->budget = $budget; $marsTourPromotion->callTrackingEnabled = true; // Criteria $criteria = array(); // Criterion - Travel Agency product service $productService = new ProductService(); $productService->text = 'Travel Agency'; $criteria[] = $productService; // Criterion - English language // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes $language = new Language(); $language->id = 1000; $criteria[] = $language; // Criterion - Within 15 miles $proximity = new Proximity(); $proximity->geoPoint = $business->geoPoint; $proximity->radiusDistanceUnits = 'MILES'; $proximity->radiusInUnits = 15; $criteria[] = $proximity; $marsTourPromotion->criteria = $criteria; // Creatives $creatives = array(); $creative1 = new Creative('Standard Mars Trip', 'Fly coach to Mars', 'Free in-flight pretzels'); $creatives[] = $creative1; $creative2 = new Creative('Deluxe Mars Trip', 'Fly first class to Mars', 'Unlimited powdered orange drink'); $creatives[] = $creative2; $marsTourPromotion->creatives = $creatives; $operations = array(); $operation = new PromotionOperation(); $operation->operand = $marsTourPromotion; $operation->operator = 'ADD'; $operations[] = $operation; $result = $promotionService->mutate($operations); $addedPromotion = $result[0]; printf("Added promotion ID %d with name '%s' to business ID %d\n", $addedPromotion->id, $addedPromotion->name, $businessId); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetAccountChangesExample(AdWordsUser $user) { // Get the service, which loads the required classes. $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION); $customerSyncService = $user->GetService('CustomerSyncService', ADWORDS_VERSION); // Get an array of all campaign ids. $campaignIds = array(); $selector = new Selector(); $selector->fields = array('Id'); $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { $page = $campaignService->get($selector); if (isset($page->entries)) { foreach ($page->entries as $campaign) { $campaignIds[] = $campaign->id; } } $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); // Set the date time range, from 24 hours ago until now. $dateTimeRange = new DateTimeRange(); $dateTimeRange->min = date('Ymd his', strtotime('-1 day')); $dateTimeRange->max = date('Ymd his'); // Create selector. $selector = new CustomerSyncSelector(); $selector->dateTimeRange = $dateTimeRange; $selector->campaignIds = $campaignIds; // Make the get request. $accountChanges = $customerSyncService->get($selector); // Display results. if (isset($accountChanges)) { printf("Most recent change: %s\n", $accountChanges->lastChangeTimestamp); if (isset($accountChanges->changedCampaigns)) { foreach ($accountChanges->changedCampaigns as $campaignChangeData) { printf("Campaign with id '%.0f' has change status '%s'.\n", $campaignChangeData->campaignId, $campaignChangeData->campaignChangeStatus); if ($campaignChangeData->campaignChangeStatus != 'NEW') { printf("\tAdded ad extensions: %s\n", ArrayToString($campaignChangeData->addedAdExtensions)); printf("\tDeleted ad extensions: %s\n", ArrayToString($campaignChangeData->deletedAdExtensions)); printf("\tAdded campaign criteria: %s\n", ArrayToString($campaignChangeData->addedCampaignCriteria)); printf("\tDeleted campaign criteria: %s\n", ArrayToString($campaignChangeData->deletedCampaignCriteria)); printf("\tCampaign targeting changed: %s\n", $campaignChangeData->campaignTargetingChanged ? 'true' : 'false'); if (isset($campaignChangeData->changedAdGroups)) { foreach ($campaignChangeData->changedAdGroups as $adGroupChangeData) { printf("\tAd Group with id '%.0f' has change status '%s'.\n", $adGroupChangeData->adGroupId, $adGroupChangeData->adGroupChangeStatus); if ($adGroupChangeData->adGroupChangeStatus != 'NEW') { printf("\t\tChanged ads: %s\n", ArrayToString($adGroupChangeData->changedAds)); printf("\t\tChanged criteria: %s\n", ArrayToString($adGroupChangeData->changedCriteria)); printf("\t\tDeleted criteria: %s\n", ArrayToString($adGroupChangeData->deletedCriteria)); } } } } } } } else { print "No changes were found.\n"; } }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the ID of the parent campaign */ function CreateAndAttachSharedKeywordSetExample(AdWordsUser $user, $campaignId) { $keywordTexts = array('mars cruise', 'mars hotels'); // Create shared negative Keyword Set. $sharedSetService = $user->GetService('SharedSetService'); $set = new SharedSet(); $set->name = sprintf('API Negative keyword list #%s', uniqid()); $set->type = 'NEGATIVE_KEYWORDS'; $operation = new SharedSetOperation(); $operation->operator = 'ADD'; $operation->operand = $set; $operations = array($operation); $result = $sharedSetService->mutate($operations); // Get the shared set ID and print it. $set = $result->value[0]; $sharedSetId = $set->sharedSetId; printf("SharedSet '%s' has been created with ID '%s'\n", $set->name, $sharedSetId); // Add negative Keywords to SharedSet. $sharedCriterionService = $user->GetService('SharedCriterionService'); $operations = array(); foreach ($keywordTexts as $keywordText) { $keyword = new Keyword(); $keyword->text = $keywordText; $keyword->matchType = 'BROAD'; $sharedCriterion = new SharedCriterion(); $sharedCriterion->criterion = $keyword; $sharedCriterion->negative = true; $sharedCriterion->sharedSetId = $sharedSetId; $operation = new SharedCriterionOperation(); $operation->operator = 'ADD'; $operation->operand = $sharedCriterion; $operations[] = $operation; } $result = $sharedCriterionService->mutate($operations); // Print the shared negative keywords. foreach ($result->value as $sharedCriterion) { printf("Shared negative Keyword '%s' created, with ID '%s'\n", $sharedCriterion->criterion->text, $sharedCriterion->criterion->id); } // Attach the articles to the campaign. $campaignSharedSetService = $user->GetService('CampaignSharedSetService'); $campaignSet = new CampaignSharedSet(); $campaignSet->campaignId = $campaignId; $campaignSet->sharedSetId = $sharedSetId; $operator = new CampaignSharedSetOperation(); $operator->operator = 'ADD'; $operator->operand = $campaignSet; $operations = array($operator); $result = $campaignSharedSetService->mutate($operations); // Print the CampaignSharedSet and its relating IDs. $campaignSet = $result->value[0]; printf("Created CampaignSharedSet with campaign ID '%s' and shared set ID '%s'\n", $campaignSet->campaignId, $campaignSet->sharedSetId); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the id of the campaign to the ad the extension to */ function AddLocationExtensionExample(AdWordsUser $user, $campaignId) { // Get the services, which loads the required classes. $geoLocationService = $user->GetService('GeoLocationService', 'v201109'); $campaignAdExtensionService = $user->GetService('CampaignAdExtensionService', 'v201109'); // Create address. $address = new Address(); $address->streetAddress = '1600 Amphitheatre Parkway'; $address->cityName = 'Mountain View'; $address->provinceCode = 'US-CA'; $address->postalCode = '94043'; $address->countryCode = 'US'; // Create geo location selector. $selector = new GeoLocationSelector(); $selector->addresses = array($address); // Make the get request. $result = $geoLocationService->get($selector); // Display result. $geoLocation = $result[0]; if ($geoLocation->GeoLocationType != 'InvalidGeoLocation') { $lat = $geoLocation->geoPoint->latitudeInMicroDegrees / AdWordsConstants::MICRO_DEGREES_PER_DEGREE; $long = $geoLocation->geoPoint->longitudeInMicroDegrees / AdWordsConstants::MICRO_DEGREES_PER_DEGREE; printf("Address with street '%s' and lat/long '%s/%s' was found.\n", $geoLocation->address->streetAddress, $lat, $long); } else { printf("Address with street '%s' could not be found.\n", $address->streetAddress); exit; } // Create location extension. $locationExtension = new LocationExtension(); $locationExtension->address = $geoLocation->address; $locationExtension->geoPoint = $geoLocation->geoPoint; $locationExtension->encodedLocation = $geoLocation->encodedLocation; $locationExtension->source = 'ADWORDS_FRONTEND'; // Set additional settings (optional). $locationExtension->companyName = 'ACME Inc.'; $locationExtension->phoneNumber = '(650) 253-0000'; // Create campaign ad extension. $campaignAdExtension = new CampaignAdExtension(); $campaignAdExtension->campaignId = $campaignId; $campaignAdExtension->adExtension = $locationExtension; // Create operation. $operation = new CampaignAdExtensionOperation(); $operation->operand = $campaignAdExtension; $operation->operator = 'ADD'; $operations = array($operation); // Make the mutate request. $result = $campaignAdExtensionService->mutate($operations); // Display result. $campaignAdExtension = $result->value[0]; printf("Location extension with street address '%s' and id '%s' was added.\n", $campaignAdExtension->adExtension->address->streetAddress, $campaignAdExtension->adExtension->id); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the ID of the campaign to add the sitelinks to */ function AddSitelinksExample(AdWordsUser $user, $campaignId) { // Get the services and load the required classes. $campaignExtensionSettingService = $user->GetService('CampaignExtensionSettingService', ADWORDS_VERSION); $customerService = $user->GetService('CustomerService', ADWORDS_VERSION); $customer = $customerService->get(); // Create the sitelinks: // A simple one. $sitelink1 = new SitelinkFeedItem(); $sitelink1->sitelinkText = 'Store Hours'; $sitelink1->sitelinkFinalUrls = new UrlList(array('http://www.example.com/storehours')); // This one to show the Thanksgiving specials link only from 20 - 27 Nov. $sitelink2 = new SitelinkFeedItem(); $sitelink2->sitelinkText = 'Thanksgiving Specials'; $sitelink2->sitelinkFinalUrls = new UrlList(array('http://www.example.com/thanksgiving')); $sitelink2->startTime = date('Y') . '1120 000000 ' . $customer->dateTimeZone; $sitelink2->endTime = date('Y') . '1127 235959 ' . $customer->dateTimeZone; // Sitelink targetted on high end mobile. $sitelink3 = new SitelinkFeedItem(); $sitelink3->sitelinkText = 'Wifi available'; $sitelink3->sitelinkFinalUrls = new UrlList(array('http://www.example.com/mobile/wifi')); $sitelink3->devicePreference = 30001; // Show the happy hours link only during Mon - Fri 6PM to 9PM. $sitelink4 = new SitelinkFeedItem(); $sitelink4->sitelinkText = 'Happy Hours Now!'; $sitelink4->sitelinkFinalUrls = new UrlList(array('http://www.example.com/happyhours')); $sitelink4->scheduling = new FeedItemScheduling(array(new FeedItemSchedule('MONDAY', 18, 'ZERO', 21, 'ZERO'), new FeedItemSchedule('TUESDAY', 18, 'ZERO', 21, 'ZERO'), new FeedItemSchedule('WEDNESDAY', 18, 'ZERO', 21, 'ZERO'), new FeedItemSchedule('THURSDAY', 18, 'ZERO', 21, 'ZERO'), new FeedItemSchedule('FRIDAY', 18, 'ZERO', 21, 'ZERO'))); // Create your campaign extension settings. This associates the sitelinks // to your campaign. $campaignExtensionSetting = new CampaignExtensionSetting(); $campaignExtensionSetting->campaignId = $campaignId; $campaignExtensionSetting->extensionType = 'SITELINK'; $campaignExtensionSetting->extensionSetting = new ExtensionSetting(); $campaignExtensionSetting->extensionSetting->extensions = array(); $campaignExtensionSetting->extensionSetting->extensions[] = $sitelink1; $campaignExtensionSetting->extensionSetting->extensions[] = $sitelink2; $campaignExtensionSetting->extensionSetting->extensions[] = $sitelink3; $campaignExtensionSetting->extensionSetting->extensions[] = $sitelink4; // Create operation. $operation = new CampaignExtensionSettingOperation(); $operation->operator = 'ADD'; $operation->operand = $campaignExtensionSetting; $operations = array($operation); // Add the sitelinks. $result = $campaignExtensionSettingService->mutate($operations); // Print the results. $newExtensionSetting = $result->value[0]; printf('Extension setting with type "%s" was added to campaign ID %d', $newExtensionSetting->extensionType, $newExtensionSetting->campaignId); return $newExtensionSetting; }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the id of the campaign to add targeting criteria to */ function AddCampaignTargetingCriteriaExample(AdWordsUser $user, $campaignId) { // Get the service, which loads the required classes. $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION); $campaignCriteria = array(); // Create locations. The IDs can be found in the documentation or retrieved // with the LocationCriterionService. $california = new Location(); $california->id = 21137; $campaignCriteria[] = new CampaignCriterion($campaignId, null, $california); $mexico = new Location(); $mexico->id = 2484; $campaignCriteria[] = new CampaignCriterion($campaignId, null, $mexico); // Create languages. The IDs can be found in the documentation or retrieved // with the ConstantDataService. $english = new Language(); $english->id = 1000; $campaignCriteria[] = new CampaignCriterion($campaignId, null, $english); $spanish = new Language(); $spanish->id = 1003; $campaignCriteria[] = new CampaignCriterion($campaignId, null, $spanish); // Create operations. $operations = array(); foreach ($campaignCriteria as $campaignCriterion) { $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); } }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetExpressBusinessesExample(AdWordsUser $user) { // Get the service, which loads the required classes. $businessService = $user->GetService('ExpressBusinessService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('Id', 'Name', 'Website', 'Address', 'GeoPoint', 'Status'); $selector->ordering[] = new OrderBy('Name', 'ASCENDING'); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $businessService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $business) { $address = $business->address !== NULL ? $business->address : new Address(); $geoPoint = $business->geoPoint; printf("Express business found with name '%s' id %s website: %s " . "address: %s,%s,%s,%s,%s geo point: %d,%d status: %s\n", $business->name, $business->id, $business->website, $address->streetAddress, $address->streetAddress2, $address->cityName, $address->provinceName, $address->postalCode, $geoPoint->latitudeInMicroDegrees, $geoPoint->longitudeInMicroDegrees, $business->status); } } else { print "No express businesses were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $adGroupId the id of the parent ad group */ function GetPlacementsExample(AdWordsUser $user, $adGroupId) { // Get the service, which loads the required classes. $adGroupCriterionService = $user->GetService('AdGroupCriterionService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('PlacementUrl', 'Id'); $selector->ordering[] = new OrderBy('PlacementUrl', 'ASCENDING'); // Create predicates. $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId)); $selector->predicates[] = new Predicate('CriteriaType', 'IN', array('PLACEMENT')); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $adGroupCriterionService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $adGroupCriterion) { printf("Placement with URL '%s' and ID '%s' was found.\n", $adGroupCriterion->criterion->url, $adGroupCriterion->criterion->id); } } else { print "No placements were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $adGroupId the id of the parent ad group */ function GetTextAdsExample(AdWordsUser $user, $adGroupId) { // Get the service, which loads the required classes. $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('Headline', 'Id'); $selector->ordering[] = new OrderBy('Headline', 'ASCENDING'); // Create predicates. $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId)); $selector->predicates[] = new Predicate('AdType', 'IN', array('TEXT_AD')); // By default disabled ads aren't returned by the selector. To return them // include the DISABLED status in a predicate. $selector->predicates[] = new Predicate('Status', 'IN', array('ENABLED', 'PAUSED', 'DISABLED')); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); 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 += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the ID of the campaign to get targeting criteria * for */ function GetCampaignTargetingCriteriaExample(AdWordsUser $user, $campaignId) { // Get the service, which loads the required classes. $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('Id', 'CriteriaType'); // Create predicates. $selector->predicates[] = new Predicate('CampaignId', 'IN', array($campaignId)); $selector->predicates[] = new Predicate('CriteriaType', 'IN', array('LANGUAGE', 'LOCATION', 'AGE_RANGE', 'CARRIER', 'OPERATING_SYSTEM_VERSION', 'GENDER', 'POLYGON', 'PROXIMITY', 'PLATFORM')); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $campaignCriterionService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $campaignCriterion) { printf("Campaign targeting criterion with ID '%s' and type '%s' was " . "found.\n", $campaignCriterion->criterion->id, $campaignCriterion->criterion->CriterionType); } } else { print "No campaign targeting criteria were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $labelId the label id to run the example with */ function GetCampaignsByLabelExample(AdWordsUser $user, $labelId) { // 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); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the ID of the campaign to get stats for */ function GetCampaignStatsExample(AdWordsUser $user) { // Get the service, which loads the required classes. $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('Id', 'Name', 'Impressions', 'Clicks', 'Cost', 'Ctr'); $selector->predicates[] = new Predicate('Impressions', 'GREATER_THAN', array(0)); // Set date range to request stats for. $dateRange = new DateRange(); $dateRange->min = date('Ymd', strtotime('-1 week')); $dateRange->max = date('Ymd', strtotime('-1 day')); $selector->dateRange = $dateRange; // 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 '%s' had the following stats " . "during the last week:\n", $campaign->name, $campaign->id); printf(" Impressions: %d\n", $campaign->campaignStats->impressions); printf(" Clicks: %d\n", $campaign->campaignStats->clicks); printf(" Cost: \$%.2f\n", $campaign->campaignStats->cost->microAmount / AdWordsConstants::MICROS_PER_DOLLAR); printf(" CTR: %.2f%%\n", $campaign->campaignStats->ctr * 100); } } else { print "No matching campaigns were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $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(AdWordsUser $user, $adGroupId, $criterionId) { // Get the service, which loads the required classes. $adGroupCriterionService = $user->GetService('AdGroupCriterionService', ADWORDS_VERSION); // Create criterion using an existing ID. Use the base class Criterion // instead of Keyword to avoid having to set keyword-specific fields. $criterion = new Criterion(); $criterion->id = $criterionId; // Create ad group criterion. $adGroupCriterion = new BiddableAdGroupCriterion(); $adGroupCriterion->adGroupId = $adGroupId; $adGroupCriterion->criterion = new Criterion($criterionId); // Update destination URL. $adGroupCriterion->destinationUrl = 'http://www.example.com/new'; // Create operation. $operation = new AdGroupCriterionOperation(); $operation->operand = $adGroupCriterion; $operation->operator = 'SET'; $operations = array($operation); // 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 AdWordsUser $user the user to run the example with * @param string $adGroupId the parent ad group id of the ads to retrieve */ function GetAllDisapprovedAdsWithAwqlExample(AdWordsUser $user, $adGroupId) { // Get the service, which loads the required classes. $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION); // Create a query. $query = sprintf('SELECT Id, AdGroupAdDisapprovalReasons WHERE AdGroupId = ' . '%d AND AdGroupCreativeApprovalStatus = DISAPPROVED ORDER BY Id', $adGroupId); // Create paging controls. $offset = 0; do { $pageQuery = sprintf('%s LIMIT %d,%d', $query, $offset, AdWordsConstants::RECOMMENDED_PAGE_SIZE); // Make the query request. $page = $adGroupAdService->query($pageQuery); // Display results. if (isset($page->entries)) { foreach ($page->entries as $adGroupAd) { printf("Ad with ID '%.0f', and type '%s' was disapproved for the " . "following reasons:\n", $adGroupAd->ad->id, $adGroupAd->ad->AdType); if (!empty($adGroupAd->disapprovalReasons)) { foreach ($adGroupAd->disapprovalReasons as $reason) { printf("\t'%s'\n", $reason); } } } } else { print "No disapproved ads were found.\n"; } // Advance the paging offset. $offset += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $offset); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $adGroupId the ID of the ad group of the ad to upgrade * @param string $adId the ID of the ad to upgrade */ function UpgradeAdUrlExample(AdWordsUser $user, $adGroupId, $adId) { // Get the service, which loads the required classes. $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION); $adGroupAd = null; // Retrieving the ad first. $selector = new Selector(); $selector->fields = array('Id', 'Url'); $selector->ordering[] = new OrderBy('Headline', 'ASCENDING'); // Restrict the fetch to only the selected ad group ID and ad ID. $selector->predicates[] = new Predicate('AdGroupId', 'EQUALS', array($adGroupId)); $selector->predicates[] = new Predicate('Id', 'EQUALS', array($adId)); $page = $adGroupAdService->get($selector); if (isset($page->entries)) { $adGroupAd = $page->entries[0]; printf("About to upgrade ad ID %d with URL '%s'.\n", $adGroupAd->ad->id, $adGroupAd->ad->url); } else { print "Ad for upgrade was not found.\n"; return; } // Proceed with URL upgrade. $upgradeUrl = new AdUrlUpgrade(); $upgradeUrl->adId = $adGroupAd->ad->id; $upgradeUrl->finalUrl = $adGroupAd->ad->url; $result = $adGroupAdService->upgradeUrl(array($upgradeUrl)); // Display results. foreach ($result as $adGroupAd) { printf("Text ad with ID %d was upgraded to final URLs: '%s'.\n", $adGroupAd->id, join(",", $adGroupAd->finalUrls)); } }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetProductServicesExample(AdWordsUser $user, $productServiceSuggestion, $localeText) { // Get the service, which loads the required classes. $productServiceService = $user->GetService('ProductServiceService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('ProductServiceText'); // Create predicates. $selector->predicates[] = new Predicate('ProductServiceText', 'EQUALS', array($productServiceSuggestion)); $selector->predicates[] = new Predicate('Locale', 'EQUALS', array($localeText)); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $productServiceService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $productService) { printf("Product/service with text '%s' found\n", $productService->text); } } else { print "No products/services were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetAdGroupBidModifiersExample(AdWordsUser $user) { // Get the service, which loads the required classes. $bidModifierService = $user->GetService('AdGroupBidModifierService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('CampaignId', 'AdGroupId', 'BidModifier', 'Id'); $selector->ordering[] = new OrderBy('CampaignId', 'ASCENDING'); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $bidModifierService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $modifier) { $value = 'none'; if (is_numeric($modifier->bidModifier)) { $value = $modifier->bidModifier; } printf("Campaign ID %d, AdGroup ID %d, Criterion ID %d has ad group " . "level modifier: %s\n", $modifier->campaignId, $modifier->adGroupId, $modifier->criterion->id, $value); } } else { print "No bid modifiers were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function LookupLocationExample(AdWordsUser $user) { // Get the service, which loads the required classes. $locationCriterionService = $user->GetService('LocationCriterionService', 'v201109'); // Location names to look up. $locationNames = array('Paris', 'Quebec', 'Spain', 'Deutschland'); // Locale to retrieve location names in. $locale = 'en'; $selector = new Selector(); $selector->fields = array('Id', 'LocationName', 'CanonicalName', 'DisplayType', 'ParentLocations', 'Reach'); // Location names must match exactly, only EQUALS and IN are supported. $selector->predicates[] = new Predicate('LocationName', 'IN', $locationNames); // Only one locale can be used in a request. $selector->predicates[] = new Predicate('Locale', 'EQUALS', $locale); // Make the get request. $locationCriteria = $locationCriterionService->get($selector); // Display results. if (isset($locationCriteria)) { foreach ($locationCriteria as $locationCriterion) { if (isset($locationCriterion->location->parentLocations)) { $parentLocations = implode(', ', array_map('GetLocationString', $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 AdWordsUser $user the user to run the example with * @param string $adGroupId the id of the parent ad group */ function GetKeywordsExample(AdWordsUser $user, $adGroupId) { // Get the service, which loads the required classes. $adGroupCriterionService = $user->GetService('AdGroupCriterionService', 'v201109_1'); // Create selector. $selector = new Selector(); $selector->fields = array('KeywordText', 'KeywordMatchType', 'Id'); $selector->ordering[] = new OrderBy('KeywordText', 'ASCENDING'); // Create predicates. $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId)); $selector->predicates[] = new Predicate('CriteriaType', 'IN', array('KEYWORD')); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_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 += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetAllImagesAndVideosExample(AdWordsUser $user) { // Get the service, which loads the required classes. $mediaService = $user->GetService('MediaService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('MediaId', 'Width', 'Height', 'MimeType', 'Name'); $selector->ordering = array(new OrderBy('MediaId', 'ASCENDING')); // Create predicates. $selector->predicates[] = new Predicate('Type', 'IN', array('IMAGE', 'VIDEO')); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $mediaService->get($selector); // Display images. if (isset($page->entries)) { foreach ($page->entries as $media) { if ($media->MediaType == 'Image') { $dimensions = MapUtils::GetMap($media->dimensions); printf("Image with dimensions '%dx%d', MIME type '%s', and id '%s' " . "was found.\n", $dimensions['FULL']->width, $dimensions['FULL']->height, $media->mimeType, $media->mediaId); } else { if ($media->MediaType == 'Video') { printf("Video with name '%s' and id '%s' was found.\n", $media->name, $media->mediaId); } } } } else { print "No images or videos were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param int $campaignId the campaign to modify */ function addProductScopeExample(AdWordsUser $user, $campaignId) { // Get the CampaignCriterionService, which loads the required classes. $campaignCriterionService = $user->GetService('CampaignCriterionService', ADWORDS_VERSION); $productScope = new ProductScope(); // This set of dimensions is for demonstration purposes only. It would be // extremely unlikely that you want to include so many dimensions in your // product scope. $productScope->dimensions[] = new ProductBrand('Nexus'); $productScope->dimensions[] = new ProductCanonicalCondition('NEW'); $productScope->dimensions[] = new ProductCustomAttribute('CUSTOM_ATTRIBUTE_0', 'my attribute value'); $productScope->dimensions[] = new ProductOfferId('book1'); $productScope->dimensions[] = new ProductType('PRODUCT_TYPE_L1', 'Media'); $productScope->dimensions[] = new ProductType('PRODUCT_TYPE_L2', 'Books'); // The value for the bidding category is a fixed ID for the 'Luggage & Bags' // category. You can retrieve IDs for categories from the ConstantDataService. // See the 'GetProductCategoryTaxonomy' example for more details. $productScope->dimensions[] = new ProductBiddingCategory('BIDDING_CATEGORY_L1', '-5914235892932915235'); $campaignCriterion = new CampaignCriterion(); $campaignCriterion->campaignId = $campaignId; $campaignCriterion->criterion = $productScope; // Create operation. $operation = new CampaignCriterionOperation(); $operation->operand = $campaignCriterion; $operation->operator = 'ADD'; // Make the mutate request. $result = $campaignCriterionService->mutate(array($operation)); printf("Created a ProductScope criterion with ID '%s'", $result->value[0]->criterion->id); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function AddExpressBusinessesExample(AdWordsUser $user) { // Get the service, which loads the required classes. $businessService = $user->GetService('ExpressBusinessService', ADWORDS_VERSION); $business1 = new ExpressBusiness(); $business1->status = 'ENABLED'; $business1->name = 'Express Interplanetary Cruise #' . uniqid(); $business1->address = new Address('1600 Amphitheatre Pkwy', null, 'Mountain View', 'CA', null, null, 'US'); $business1->website = 'http://www.example.com/cruise1'; $business2 = new ExpressBusiness(); $business2->status = 'ENABLED'; $business2->name = 'Express Interplanetary Cruise #' . uniqid(); $business2->address = new Address('1600 Amphitheatre Pkwy', null, 'Mountain View', 'CA', null, null, 'US'); $business2->website = 'http://www.example.com/cruise2'; $operations = array(); $operation1 = new ExpressBusinessOperation(); $operation1->operand = $business1; $operation1->operator = 'ADD'; $operations[] = $operation1; $operation2 = new ExpressBusinessOperation(); $operation2->operand = $business2; $operation2->operator = 'ADD'; $operations[] = $operation2; $addedBusinesses = $businessService->mutate($operations); foreach ($addedBusinesses as $addedBusiness) { printf("Added express business with ID %d and name '%s'\n", $addedBusiness->id, $addedBusiness->name); } }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with * @param string $campaignId the id of the campaign to modify * @param float $bidModifier the multiplier to set on the campaign */ function SetBidModifierExample(AdWordsUser $user, $campaignId, $bidModifier) { // Get the CampaignCriterionService, also loads classes $campaignCriterionService = $user->GetService("CampaignCriterionService", ADWORDS_VERSION); // Create Mobile Platform. The ID can be found in the documentation. // https://developers.google.com/adwords/api/docs/appendix/platforms $mobile = new Platform(); $mobile->id = 30001; // HighEndMobile = 30001 // Create criterion with modified bid. $criterion = new CampaignCriterion(); $criterion->campaignId = $campaignId; $criterion->criterion = $mobile; $criterion->bidModifier = $bidModifier; // Create SET operation. $operation = new CampaignCriterionOperation(); $operation->operator = "SET"; $operation->operand = $criterion; // Update campaign criteria. $results = $campaignCriterionService->mutate(array($operation)); // Display campaign criteria. if (count($results->value)) { foreach ($results->value as $campaignCriterion) { printf("Campaign criterion with campaign ID '%s', criterion ID '%s', " . "and type '%s' was modified with bid %.2f.\n", $campaignCriterion->campaignId, $campaignCriterion->criterion->id, $campaignCriterion->criterion->type, $campaignCriterion->bidModifier); } return true; } print "No campaign criterias were modified."; }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetCampaignsExample(AdWordsUser $user) { // Get the service, which loads the required classes. $campaignService = $user->GetService('CampaignService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('Id', 'Name'); $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 '%s' was found.\n", $campaign->name, $campaign->id); } } else { print "No campaigns were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetAccountAlertsExample(AdWordsUser $user) { // Get the service, which loads the required classes. $alertService = $user->GetService('AlertService', ADWORDS_VERSION); // Create alert query. $alertQuery = new AlertQuery(); $alertQuery->clientSpec = 'ALL'; $alertQuery->filterSpec = 'ALL'; $alertQuery->types = array('ACCOUNT_BUDGET_BURN_RATE', 'ACCOUNT_BUDGET_ENDING', 'ACCOUNT_ON_TARGET', 'CAMPAIGN_ENDED', 'CAMPAIGN_ENDING', 'CREDIT_CARD_EXPIRING', 'DECLINED_PAYMENT', 'MANAGER_LINK_PENDING', 'MISSING_BANK_REFERENCE_NUMBER', 'PAYMENT_NOT_ENTERED', 'TV_ACCOUNT_BUDGET_ENDING', 'TV_ACCOUNT_ON_TARGET', 'TV_ZERO_DAILY_SPENDING_LIMIT', 'USER_INVITE_ACCEPTED', 'USER_INVITE_PENDING', 'ZERO_DAILY_SPENDING_LIMIT'); $alertQuery->severities = array('GREEN', 'YELLOW', 'RED'); $alertQuery->triggerTimeSpec = 'ALL_TIME'; // Create selector. $selector = new AlertSelector(); $selector->query = $alertQuery; // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $alertService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $alert) { printf("Alert of type '%s' and severity '%s' for account '%d' was " . "found.\n", $alert->alertType, $alert->alertSeverity, $alert->clientCustomerId); } } else { print "No alerts were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function AddConversionTrackerExample(AdWordsUser $user) { // Get the service, which loads the required classes. $conversionTrackerService = $user->GetService('ConversionTrackerService', ADWORDS_VERSION); // Create conversion tracker. $conversionTracker = new AdWordsConversionTracker(); $conversionTracker->name = 'Interplanetary Cruise Conversion #' . uniqid(); // Set additional settings (optional). $conversionTracker->status = 'ENABLED'; $conversionTracker->category = 'DEFAULT'; $conversionTracker->viewthroughLookbackWindow = 15; $conversionTracker->isProductAdsChargeable = TRUE; $conversionTracker->productAdsChargeableConversionWindow = 15; $conversionTracker->markupLanguage = 'HTML'; $conversionTracker->textFormat = 'HIDDEN'; $conversionTracker->conversionPageLanguage = 'en'; $conversionTracker->backgroundColor = '#0000FF'; // Create operation. $operation = new ConversionTrackerOperation(); $operation->operand = $conversionTracker; $operation->operator = 'ADD'; $operations = array($operation); // Make the mutate request. $result = $conversionTrackerService->mutate($operations); // Display result. $conversionTracker = $result->value[0]; printf("Conversion type with name '%s' and ID '%.0f' was added.\n", $conversionTracker->name, $conversionTracker->id); printf("Tag code:\n%s\n", $conversionTracker->snippet); }
/** * Runs the example. * @param AdWordsUser $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(AdWordsUser $user, $adGroupId, $adId) { // Get the service, which loads the required classes. $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION); // Create ad using an existing ID. Use the base class Ad instead of TextAd to // avoid having to set ad-specific fields. $ad = new Ad(); $ad->id = $adId; // Create ad group ad. $adGroupAd = new AdGroupAd(); $adGroupAd->adGroupId = $adGroupId; $adGroupAd->ad = $ad; // Update the status. $adGroupAd->status = 'PAUSED'; // Create operation. $operation = new 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 AdWordsUser $user the user to run the example with * @param string $adGroupId the parent ad group id of the ads to retrieve */ function GetAllDisapprovedAdsExample(AdWordsUser $user, $adGroupId) { // Get the service, which loads the required classes. $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION); // Create selector. $selector = new Selector(); $selector->fields = array('Id', 'AdGroupAdDisapprovalReasons'); $selector->ordering = array(new OrderBy('Id', 'ASCENDING')); // Create predicates. $selector->predicates[] = new Predicate('AdGroupId', 'IN', array($adGroupId)); $selector->predicates[] = new Predicate('AdGroupCreativeApprovalStatus', 'IN', array('DISAPPROVED')); // Create paging controls. $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $adGroupAdService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $adGroupAd) { printf("Ad with ID '%.0f', and type '%s' was disapproved for the " . "following reasons:\n", $adGroupAd->ad->id, $adGroupAd->ad->AdType); if (!empty($adGroupAd->disapprovalReasons)) { foreach ($adGroupAd->disapprovalReasons as $reason) { printf("\t'%s'\n", $reason); } } } } else { print "No disapproved ads were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }