本文整理汇总了PHP中AdWordsUser::GetService方法的典型用法代码示例。如果您正苦于以下问题:PHP AdWordsUser::GetService方法的具体用法?PHP AdWordsUser::GetService怎么用?PHP AdWordsUser::GetService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdWordsUser
的用法示例。
在下文中一共展示了AdWordsUser::GetService方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: AddTextAdsExample
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);
}
}
示例2: UploadOfflineConversionsExample
/**
* 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);
}
示例3: AddPromotionExample
/**
* 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);
}
示例4: GetAccountChangesExample
/**
* 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";
}
}
示例5: CreateAndAttachSharedKeywordSetExample
/**
* 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);
}
示例6: AddLocationExtensionExample
/**
* 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);
}
示例7: AddSitelinksExample
/**
* 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;
}
示例8: AddCampaignTargetingCriteriaExample
/**
* 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);
}
}
示例9: GetExpressBusinessesExample
/**
* 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);
}
示例10: GetPlacementsExample
/**
* 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);
}
示例11: GetTextAdsExample
/**
* 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);
}
示例12: GetCampaignTargetingCriteriaExample
/**
* 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);
}
示例13: GetCampaignsByLabelExample
/**
* 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);
}
示例14: GetCampaignStatsExample
/**
* 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);
}
示例15: UpdateKeywordExample
/**
* 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);
}