本文整理汇总了PHP中AdWordsUser类的典型用法代码示例。如果您正苦于以下问题:PHP AdWordsUser类的具体用法?PHP AdWordsUser怎么用?PHP AdWordsUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdWordsUser类的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: GetPromotionsExample
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
*/
function GetPromotionsExample(AdWordsUser $user, $businessId)
{
$user->SetExpressBusinessId($businessId);
// Get the service, which loads the required classes.
$promotionService = $user->GetService('PromotionService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('PromotionId', '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 = $promotionService->get($selector);
// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $promotion) {
printf("Express promotion found with name '%s' " . "id %s destinationUrl: %s\n", $promotion->name, $promotion->id, $promotion->destinationUrl);
}
} else {
print "No express promotions were found.\n";
}
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
}
示例3: 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);
}
示例4: addProductScopeExample
/**
* 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);
}
示例5: DownloadCriteriaReportExample
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $filePath the path of the file to download the report to
*/
function DownloadCriteriaReportExample(AdWordsUser $user, $filePath)
{
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('CampaignId', 'AdGroupId', 'Id', 'Criteria', 'CriteriaType', 'Impressions', 'Clicks', 'Cost');
// Optional: use predicate to filter out paused criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('PAUSED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Criteria performance report #' . uniqid();
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->reportType = 'CRITERIA_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
// Exclude criteria that haven't recieved any impressions over the date range.
$reportDefinition->includeZeroImpressions = false;
// Set additional options.
$options = array('version' => ADWORDS_VERSION);
// Optional: Set skipReportHeader, skipColumnHeader, skipReportSummary to
// suppress headers or summary rows.
// $options['skipReportHeader'] = true;
// $options['skipColumnHeader'] = true;
// $options['skipReportSummary'] = true;
// Optional: Set includeZeroImpressions to include zero impression rows in
// the report output.
// $options['includeZeroImpressions'] = true;
// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}
示例6: 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);
}
示例7: 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);
}
示例8: AddConversionTrackerExample
/**
* 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);
}
示例9: LookupLocationExample
/**
* 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";
}
}
示例10: 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);
}
示例11: 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);
}
示例12: 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);
}
示例13: GetAllImagesAndVideosExample
/**
* 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);
}
示例14: AddLocationExtensionOverrideExample
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
* @param string $adId the id the ad to add the override to
* @param string $campaignAdExtensionId the id of an existings campaign ad
* extension to override with
*/
function AddLocationExtensionOverrideExample(AdWordsUser $user, $adId, $campaignAdExtensionId)
{
// Get the service, which loads the required classes.
$adExtensionOverrideService = $user->GetService('AdExtensionOverrideService', ADWORDS_VERSION);
// Create ad extenstion override.
$adExtensionOverride = new AdExtensionOverride();
$adExtensionOverride->adId = $adId;
// Create ad extension using existing id.
$adExtension = new AdExtension();
$adExtension->id = $campaignAdExtensionId;
$adExtensionOverride->adExtension = $adExtension;
// Set override info (optional).
$locationOverrideInfo = new LocationOverrideInfo();
$locationOverrideInfo->radius = 5;
$locationOverrideInfo->radiusUnits = 'MILES';
$overrideInfo = new OverrideInfo();
$overrideInfo->LocationOverrideInfo = $locationOverrideInfo;
$adExtensionOverride->overrideInfo = $overrideInfo;
// Create operations.
$operation = new AdExtensionOverrideOperation();
$operation->operand = $adExtensionOverride;
$operation->operator = 'ADD';
$operations = array($operation);
// Make the mutate request.
$result = $adExtensionOverrideService->mutate($operations);
// Display results.
if (isset($result->value)) {
foreach ($result->value as $adExtensionOverride) {
print 'Ad extension override with ad id "' . $adExtensionOverride->adId . '", ad extension id "' . $adExtensionOverride->adExtension->id . '", and type "' . $adExtensionOverride->adExtension->AdExtensionType . "\" was added.\n";
}
} else {
print "No ad extension overrides were added.\n";
}
}
示例15: GetCampaignsExample
/**
* 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);
}