/** * 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 */ function GetKeywordIdeasExample(AdWordsUser $user) { // Get the service, which loads the required classes. $targetingIdeaService = $user->GetService('TargetingIdeaService', ADWORDS_VERSION); // Create selector. $selector = new TargetingIdeaSelector(); $selector->requestType = 'IDEAS'; $selector->ideaType = 'KEYWORD'; $selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES'); // Create seed keyword. $keyword = 'mars cruise'; // Create related to query search parameter. $relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); $relatedToQuerySearchParameter->queries = array($keyword); $selector->searchParameters[] = $relatedToQuerySearchParameter; // Create language search parameter (optional). // The ID can be found in the documentation: // https://developers.google.com/adwords/api/docs/appendix/languagecodes // Note: As of v201302, only a single language parameter is allowed. $languageParameter = new LanguageSearchParameter(); $english = new Language(); $english->id = 1000; $languageParameter->languages = array($english); $selector->searchParameters[] = $languageParameter; // Create network search parameter (optional). $networkSetting = new NetworkSetting(); $networkSetting->targetGoogleSearch = true; $networkSetting->targetSearchNetwork = false; $networkSetting->targetContentNetwork = false; $networkSetting->targetPartnerSearchNetwork = false; $networkSearchParameter = new NetworkSearchParameter(); $networkSearchParameter->networkSetting = $networkSetting; $selector->searchParameters[] = $networkSearchParameter; // Set selector paging (required by this service). $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $targetingIdeaService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $targetingIdea) { $data = MapUtils::GetMap($targetingIdea->data); $keyword = $data['KEYWORD_TEXT']->value; $search_volume = isset($data['SEARCH_VOLUME']->value) ? $data['SEARCH_VOLUME']->value : 0; if ($data['CATEGORY_PRODUCTS_AND_SERVICES']->value === null) { $categoryIds = ''; } else { $categoryIds = implode(', ', $data['CATEGORY_PRODUCTS_AND_SERVICES']->value); } printf("Keyword idea with text '%s', category IDs (%s) and average " . "monthly search volume '%s' was found.\n", $keyword, $categoryIds, $search_volume); } } else { print "No keywords ideas 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 UploadImageExample(AdWordsUser $user) { // Get the service, which loads the required classes. $mediaService = $user->GetService('MediaService', ADWORDS_VERSION); // Create image. $image = new Image(); $image->data = MediaUtils::GetBase64Data('http://goo.gl/HJM3L'); $image->type = 'IMAGE'; // Make the upload request. $result = $mediaService->upload(array($image)); // Display result. $image = $result[0]; $dimensions = MapUtils::GetMap($image->dimensions); printf("Image with dimensions '%dx%d', MIME type '%s', and id '%s' was " . "uploaded.\n", $dimensions['FULL']->width, $dimensions['FULL']->height, $image->mimeType, $image->mediaId); }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function UploadMediaBundleExample(AdWordsUser $user) { // Get the service, which loads the required classes. $mediaService = $user->GetService('MediaService', ADWORDS_VERSION); // Create HTML5 media. $html5Zip = new MediaBundle(); $html5Zip->data = MediaUtils::GetBase64Data('https://goo.gl/9Y7qI2'); $html5Zip->type = 'MEDIA_BUNDLE'; // Make the upload request. $result = $mediaService->upload(array($html5Zip)); // Display result. $mediaBundle = $result[0]; $dimensions = MapUtils::GetMap($mediaBundle->dimensions); printf("HTML5 media with ID %d, dimensions '%dx%d', MIME type '%s' was " . "uploaded.\n", $mediaBundle->mediaId, $dimensions['FULL']->width, $dimensions['FULL']->height, $mediaBundle->mimeType); }
function GetKeywordIdeas($adVersion, \AdWordsUser $user, $keywords) { $result = []; // Get the service, which loads the required classes. $targetingIdeaService = $user->GetService('TargetingIdeaService', $adVersion); // Create selector. $selector = new \TargetingIdeaSelector(); $selector->requestType = 'STATS'; $selector->ideaType = 'KEYWORD'; $selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES'); $locationParameter = new \LocationSearchParameter(); $unitedStates = new \Location(); $unitedStates->id = 2840; $locationParameter->locations = [$unitedStates]; $networkParameter = new \NetworkSearchParameter(); $networdSettings = new \NetworkSetting(); $networdSettings->targetGoogleSearch = true; $networdSettings->targetSearchNetwork = false; $networdSettings->targetContentNetwork = false; $networdSettings->targetPartnerSearchNetwork = false; $networkParameter->networkSetting = $networdSettings; // Create related to query search parameter. $relatedToQuerySearchParameter = new \RelatedToQuerySearchParameter(); $relatedToQuerySearchParameter->queries = $keywords; $selector->searchParameters[] = $relatedToQuerySearchParameter; $selector->searchParameters[] = $locationParameter; $selector->searchParameters[] = $networkParameter; // Set selector paging (required by this service). $selector->paging = new \Paging(0, \AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $targetingIdeaService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $targetingIdea) { $data = \MapUtils::GetMap($targetingIdea->data); $saerchValue = isset($data['SEARCH_VOLUME']->value) ? $data['SEARCH_VOLUME']->value : 0; $result[] = ['keyword' => $data['KEYWORD_TEXT']->value, 'value' => $saerchValue]; } } else { print "No keywords ideas were found.\n"; } // Advance the paging index. $selector->paging->startIndex += \AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); return $result; }
public function getOrdersByCompanyId($id = false) { if (!$id) { return; } $path = dirname(__FILE__) . '/dfp/src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; $token = "company_orders_" . $id; if (($data = Cache::read($token, "5min")) === false) { $data = array(); try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the OrderService. $orderService = $user->GetOrderService('v201108'); // Set the ID of the advertiser (company) to get orders for. $advertiserId = (double) $id; // Create bind variables. $vars = MapUtils::GetMapEntries(array('advertiserId' => new NumberValue($advertiserId))); // Create a statement to only select orders for a given advertiser. $filterStatement = new Statement("WHERE advertiserId = :advertiserId LIMIT 500", $vars); // Get orders by statement. $page = $orderService->getOrdersByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $k => $order) { $data[$k]['id'] = $order->id; $data[$k]['name'] = $order->name; $data[$k]['advertiserId'] = $order->advertiserId; } } Cache::write($token, $data, "5min"); } catch (Exception $e) { die($e->getMessage()); } } return $data; }
/** * Runs the example. * @param AdWordsUser $user the user to run the example with */ function GetKeywordIdeasExample(AdWordsUser $user) { // Get the service, which loads the required classes. $targetingIdeaService = $user->GetService('TargetingIdeaService', 'v201109_1'); // Create seed keyword. $keyword = new Keyword(); $keyword->text = 'mars cruise'; $keyword->matchType = 'BROAD'; // Create selector. $selector = new TargetingIdeaSelector(); $selector->requestType = 'IDEAS'; $selector->ideaType = 'KEYWORD'; $selector->requestedAttributeTypes = array('CRITERION', 'AVERAGE_TARGETED_MONTHLY_SEARCHES', 'CATEGORY_PRODUCTS_AND_SERVICES'); // Create related to keyword search parameter. $selector->searchParameters[] = new RelatedToKeywordSearchParameter(array($keyword)); // Create keyword match type search parameter to ensure unique results. $selector->searchParameters[] = new KeywordMatchTypeSearchParameter(array('BROAD')); // Set selector paging (required by this service). $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $targetingIdeaService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $targetingIdea) { $data = MapUtils::GetMap($targetingIdea->data); $keyword = $data['CRITERION']->value; $averageMonthlySearches = isset($data['AVERAGE_TARGETED_MONTHLY_SEARCHES']->value) ? $data['AVERAGE_TARGETED_MONTHLY_SEARCHES']->value : 0; $categoryIds = implode(', ', $data['CATEGORY_PRODUCTS_AND_SERVICES']->value); printf("Keyword idea with text '%s', match type '%s', category IDs " . "(%s) and average monthly search volume '%s' was found.\n", $keyword->text, $keyword->matchType, $categoryIds, $averageMonthlySearches); } } else { print "No keywords ideas 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 GetPlacementIdeasExample(AdWordsUser $user) { // Get the service, which loads the required classes. $targetingIdeaService = $user->GetService('TargetingIdeaService', ADWORDS_VERSION); // Create seed url. $url = 'mars.google.com'; // Create selector. $selector = new TargetingIdeaSelector(); $selector->requestType = 'IDEAS'; $selector->ideaType = 'PLACEMENT'; $selector->requestedAttributeTypes = array('CRITERION', 'PLACEMENT_TYPE'); // Create related to url search parameter. $relatedToUrlSearchParameter = new RelatedToUrlSearchParameter(); $relatedToUrlSearchParameter->urls = array($url); $relatedToUrlSearchParameter->includeSubUrls = FALSE; $selector->searchParameters[] = $relatedToUrlSearchParameter; // Set selector paging (required by this service). $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $targetingIdeaService->get($selector); // Display related placements. if (isset($page->entries)) { foreach ($page->entries as $targetingIdea) { $data = MapUtils::GetMap($targetingIdea->data); $placement = $data['CRITERION']->value; $placementType = $data['PLACEMENT_TYPE']->value; printf("Placement with url '%s' and type '%s' was found.\n", $placement->url, $placementType); } } else { print "No related 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 */ function GetKeywordIdeasExample(AdWordsUser $user) { // Get the service, which loads the required classes. $targetingIdeaService = $user->GetService('TargetingIdeaService', ADWORDS_VERSION); // Create seed keyword. $keyword = 'mars cruise'; // Create selector. $selector = new TargetingIdeaSelector(); $selector->requestType = 'IDEAS'; $selector->ideaType = 'KEYWORD'; $selector->requestedAttributeTypes = array('KEYWORD_TEXT', 'SEARCH_VOLUME', 'CATEGORY_PRODUCTS_AND_SERVICES'); // Create related to query search parameter. $relatedToQuerySearchParameter = new RelatedToQuerySearchParameter(); $relatedToQuerySearchParameter->queries = array($keyword); $selector->searchParameters[] = $relatedToQuerySearchParameter; // Set selector paging (required by this service). $selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE); do { // Make the get request. $page = $targetingIdeaService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $targetingIdea) { $data = MapUtils::GetMap($targetingIdea->data); $keyword = $data['KEYWORD_TEXT']->value; $search_volume = isset($data['SEARCH_VOLUME']->value) ? $data['SEARCH_VOLUME']->value : 0; $categoryIds = implode(', ', $data['CATEGORY_PRODUCTS_AND_SERVICES']->value); printf("Keyword idea with text '%s', category IDs (%s) and average " . "monthly search volume '%s' was found.\n", $keyword, $categoryIds, $search_volume); } } else { print "No keywords ideas were found.\n"; } // Advance the paging index. $selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); }
/** * Creates a new object of the given type, using the optional parameters. * When pseudo-namespace support is enabled class names can become very long, * and this function provides an alternative way to create objects that is * more readable. * @param string $type the type of object to create * @param array $params parameters to pass into the constructor, as either * flat array in the correct order for the constructor or as an * associative array from parameter name to value * @return mixed a new instance of a class that represents that type */ public function Create($type, $params = null) { if (array_key_exists($type, $this->options['classmap'])) { $class = $this->options['classmap'][$type]; $reflectionClass = new ReflectionClass($class); if (isset($params)) { if (MapUtils::IsMap($params)) { $params = MapUtils::MapToMethodParameters($params, $reflectionClass->getConstructor()); } return $reflectionClass->newInstanceArgs($params); } else { return $reflectionClass->newInstance(); } } else { trigger_error('Unknown type: ' . $type, E_USER_ERROR); } }
/** * Test converting a map to a set of method parameters. * @param array $map the map of parameter names to values * @param array $expected the expected array of parameter values * @covers MapUtils::MapToMethodParameters * @dataProvider MapToMethodParametersProvider */ public function testMapToMethodParameters(array $map, array $expected) { $reflectionClass = new ReflectionClass($this); $reflectionMethod = $reflectionClass->getMethod('SampleMethod'); $result = MapUtils::MapToMethodParameters($map, $reflectionMethod); $this->assertEquals($expected, $result); }
require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the LineItemService. $lineItemService = $user->GetService('LineItemService', 'v201411'); // Set the IDs of the custom fields, custom field option, and line item. $customFieldId = "INSERT_CUSTOM_FIELD_ID_HERE"; $dropDownCustomFieldId = "INSERT_DROP_DOWN_CUSTOM_FIELD_ID_HERE"; $customFieldOptionId = "INSERT_CUSTOM_FIELD_OPTION_ID_HERE"; $lineItemId = "INSERT_LINE_ITEM_ID_HERE"; // Create a statement to select a single line item by ID. $vars = MapUtils::GetMapEntries(array('id' => new NumberValue($lineItemId))); $filterStatement = new Statement("WHERE id = :id ORDER BY id ASC LIMIT 1", $vars); // Get the line item. $page = $lineItemService->getLineItemsByStatement($filterStatement); $lineItem = $page->results[0]; // Create custom field values. $customFieldValues = array(); $customFieldValue = new CustomFieldValue(); $customFieldValue->customFieldId = $customFieldId; $customFieldValue->value = new TextValue("Custom field value"); $customFieldValues[] = $customFieldValue; $dropDownCustomFieldValue = new DropDownCustomFieldValue(); $dropDownCustomFieldValue->customFieldId = $dropDownCustomFieldId; $dropDownCustomFieldValue->customFieldOptionId = $customFieldOptionId; $customFieldValues[] = $dropDownCustomFieldValue; // Only add existing custom field values for different custom fields than
// $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CompanyService. $companyService = $user->GetService('CompanyService', 'v201408'); // Create bind variables. $vars = MapUtils::GetMapEntries(array('type' => new TextValue('ADVERTISER'))); // Create a statement to only select companies that are advertisers sorted // by name. $filterStatement = new Statement("WHERE type = :type ORDER BY name LIMIT 500", $vars); // Get companies by statement. $page = $companyService->getCompaniesByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $company) { print $i . ') Company with ID "' . $company->id . '", name "' . $company->name . '", and type "' . $company->type . "\" was found.\n"; $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (OAuth2Exception $e) {
set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the UserService. $userService = $user->GetService('UserService', 'v201306'); // Set the ID of the user to deactivate. $userId = 'INSERT_USER_ID_HERE'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('id' => new NumberValue($userId))); // Create statement text to get user by id. $filterStatementText = "WHERE id = :id"; $offset = 0; do { // Create statement to page through results. $filterStatement = new Statement($filterStatementText . " LIMIT 500 OFFSET " . $offset, $vars); // Get users by statement. $page = $userService->getUsersByStatement($filterStatement); // Display results. $userIds = array(); if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $usr) { print $i . ') User with ID "' . $usr->id . '", email "' . $usr->email . '", and status "' . ($usr->isActive ? 'ACTIVE' : 'INACTIVE') . "\" will be deactivated.\n"; $i++;
set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Dfp/Util/DateTimeUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the OrderService. $orderService = $user->GetService('OrderService', 'v201308'); // Create a datetime representing today. $today = date(DateTimeUtils::$DFP_DATE_TIME_STRING_FORMAT, strtotime('now')); // Create bind variables. $vars = MapUtils::GetMapEntries(array('today' => new TextValue($today))); // Create statement text to get all draft and pending approval orders that // haven't ended and aren't archived. $filterStatementText = "WHERE status IN ('DRAFT', 'PENDING_APPROVAL') " . "AND endDateTime >= :today " . "AND isArchived = FALSE "; $offset = 0; do { // Create statement to page through results. $filterStatement = new Statement($filterStatementText . " LIMIT 500 OFFSET " . $offset, $vars); // Get orders by statement. $page = $orderService->getOrdersByStatement($filterStatement); // Display results. $orderIds = array(); if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $order) { // Archived orders cannot be approved.
// DfpUser.php directly via require_once. // $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the LabelService. $labelService = $user->GetService('LabelService', 'v201108'); // Create bind variables. $vars = MapUtils::GetMapEntries(array('type' => new TextValue('COMPETITIVE_EXCLUSION'))); // Create a statement to only select labels that are advertisers sorted // by name. $filterStatement = new Statement("WHERE type = :type ORDER BY name LIMIT 500", $vars); // Get labels by statement. $page = $labelService->getLabelsByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $label) { printf("%d) Label with ID '%s', name '%s', and type '%s' was found.\n", $i, $label->id, $label->name, $label->type); $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (Exception $e) {
// $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the ThirdPartySlotService. $thirdPartySlotService = $user->GetService('ThirdPartySlotService', 'v201211'); // Create a statement to get one active third party slot. $filterStatement = new Statement('WHERE status = :status LIMIT 1', MapUtils::GetMapEntries(array('status' => new TextValue('ACTIVE')))); // Get third party slots by statement. $page = $thirdPartySlotService->getThirdPartySlotsByStatement($filterStatement); if (isset($page->results)) { $thirdPartySlot = $page->results[0]; // Update the local third party slot by changing its description. $thirdPartySlot->description = 'Updated description'; // Update the third party slot on the server. $thirdPartySlot = $thirdPartySlotService->updateThirdPartySlot($thirdPartySlot); // Display results. if (isset($thirdPartySlot)) { printf("Third party slot with ID '%s' and description '%s' was " . "updated.\n", $thirdPartySlot->id, $thirdPartySlot->description); } else { print "The third party slot was not updated.\n"; } } else {
set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once 'Google/Api/Ads/Dfp/Util/Pql.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the PublisherQueryLanguageService. $pqlService = $user->GetService('PublisherQueryLanguageService', 'v201311'); // Set the type of geo target. $geoTargetType = 'City'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('type' => new TextValue($geoTargetType))); // Statement parts to help build a statement to select all targetable cities. $pqlTemplate = "SELECT Id, Name, CanonicalParentId, ParentIds, CountryCode, " . "Type, Targetable FROM Geo_Target WHERE Type = :type AND Targetable = " . "true ORDER BY CountryCode ASC, Name ASC LIMIT %d OFFSET %d "; $SUGGESTED_PAGE_LIMIT = 500; $offset = 0; $i = 0; do { // Get all cities. $resultSet = $pqlService->select(new Statement(sprintf($pqlTemplate, $SUGGESTED_PAGE_LIMIT, $offset), $vars)); // Combine result sets with previous ones. $combinedResultSet = !isset($combinedResultSet) ? $resultSet : Pql::CombineResultSets($combinedResultSet, $resultSet); printf("%d) %d geo targets beginning at offset %d were found.\n", $i++, count($resultSet->rows), $offset); $offset += $SUGGESTED_PAGE_LIMIT; } while (isset($resultSet->rows) && count($resultSet->rows) > 0); // Change to your file location. $filePath = sprintf("%s/%s-%s.csv", sys_get_temp_dir(), $geoTargetType, uniqid());
require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CustomTargetingService. $customTargetingService = $user->GetCustomTargetingService('v201104'); // Set ID of the custom targeting key to delete values from. $keyId = (double) 'INSERT_CUSTOM_TARGETING_KEY_ID_HERE'; // Create statement text to only select custom values by the given custom // targeting key ID. $filterStatementText = 'WHERE customTargetingKeyId = :keyId'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('keyId' => new NumberValue($keyId))); $offset = 0; $valueIds = array(); do { // Create statement to page through results. $filterStatement = new Statement($filterStatementText . ' LIMIT 500 OFFSET ' . $offset, $vars); // Get custom targeting values by statement. $page = $customTargetingService->getCustomTargetingValuesByStatement($filterStatement); if (isset($page->results)) { foreach ($page->results as $customTargetingValue) { $valueIds[] = $customTargetingValue->id; } } $offset += 500; } while ($offset < $page->totalResultSetSize); printf("Number of custom targeting values to be deleted: %d\n", sizeof($valueIds));
/** * @param string $adVersion * @param \AdWordsUser $user * @param array $keywords * @return array */ public static function getIdeasByKeywords($adVersion, \AdWordsUser $user, $keywords) { $result = []; // Get the service, which loads the required classes. $targetingIdeaService = $user->GetService('TargetingIdeaService', $adVersion); $selector = self::getIdeasSelector(); // Create related to query search parameter. $relatedToQuerySearchParameter = new \RelatedToQuerySearchParameter(); $relatedToQuerySearchParameter->queries = $keywords; $selector->searchParameters[] = $relatedToQuerySearchParameter; do { // Make the get request. $page = $targetingIdeaService->get($selector); // Display results. if (isset($page->entries)) { foreach ($page->entries as $targetingIdea) { $data = \MapUtils::GetMap($targetingIdea->data); $result[] = ['keyword' => $data[self::ATTRIBUTE_KEYWORD_TEXT]->value]; } } else { print "No keywords ideas were found.\n"; } // Advance the paging index. $selector->paging->startIndex += \AdWordsConstants::RECOMMENDED_PAGE_SIZE; } while ($page->totalNumEntries > $selector->paging->startIndex); return $result; }
set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CustomTargetingService. $customTargetingService = $user->GetService('CustomTargetingService', 'v201306'); // Set the ID of the custom targeting key to get custom targeting values for. $valueId = 'INSERT_CUSTOM_TARGETING_KEY_ID_HERE'; // Create a statement to only select custom targeting values for a given key. $filterStatement = new Statement('WHERE customTargetingKeyId = :keyId LIMIT 500', MapUtils::GetMapEntries(array('keyId' => new NumberValue($valueId)))); // Get custom targeting keys by statement. $page = $customTargetingService->getCustomTargetingValuesByStatement($filterStatement); if (isset($page->results)) { $values = $page->results; // Update each local custom targeting value object by changing its display // name. foreach ($values as $value) { if (empty($value->displayName)) { $value->displayName = $value->name; } $value->displayName .= ' (Deprecated)'; } // Update the custom targeting values on the server. $values = $customTargetingService->updateCustomTargetingValues($values); // Display results.
// $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the PlacementService. $placementService = $user->GetService('PlacementService', 'v201405'); // Create bind variables. $vars = MapUtils::GetMapEntries(array('status' => new TextValue('ACTIVE'))); // Create a statement to only select active placements. $filterStatement = new Statement("WHERE status = :status LIMIT 500", $vars); // Get placements by statement. $page = $placementService->getPlacementsByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $placement) { print $i . ') Placement with ID "' . $placement->id . '", name "' . $placement->name . '", and status "' . $placement->status . "\" was found.\n"; $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e);
$path = dirname(__FILE__) . '/../../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CreativeSetService. $creativeSetService = $user->GetService('CreativeSetService', 'v201311'); $masterCreativeID = 'INSERT_MASTER_CREATIVE_ID_HERE'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('masterCreativeId' => new NumberValue($masterCreativeID))); // Create a statement object to only select creative sets that have the given // master creative. $filterStatement = new Statement("WHERE masterCreativeId = :masterCreativeId LIMIT 500", $vars); // Get creative sets by statement. $page = $creativeSetService->getCreativeSetsByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $creativeSet) { printf("A creative set with ID '%s', name '%s', master creative ID '%s' " . ", and companion creativeID(s) {%s} was found.\n", $creativeSet->id, $creativeSet->name, $creativeSet->masterCreativeId, join(',', $creativeSet->companionCreativeIds)); $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (OAuth2Exception $e) {
// $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CreativeWrapperService. $creativeWrapperService = $user->GetCreativeWrapperService('v201403'); $labelId = 'INSERT_LABEL_ID_HERE'; // Create a query to select the active creative wrappers for the given label. $vars = MapUtils::GetMapEntries(array('status' => new TextValue('ACTIVE'), 'labelId' => new NumberValue($labelId))); $filterStatement = new Statement('WHERE status = :status AND labelId = :labelId', $vars); // Get creative wrappers by statement. $page = $creativeWrapperService->getCreativeWrappersByStatement($filterStatement); // Display results. if (isset($page->results)) { foreach ($page->results as $creativeWrapper) { printf("Creative wrapper with ID '%s' applying to label '%s' with" . " status '%s' will be deactivated.\n", $creativeWrapper->id, $creativeWrapper->labelId, $creativeWrapper->status); } } printf("Number of creative wrappers to be deactivated: %s\n", $page->totalResultSetSize); // Perform action. $result = $creativeWrapperService->performCreativeWrapperAction(new DeactivateCreativeWrappers(), $filterStatement); // Display results. if (isset($result) && $result->numChanges > 0) { printf("Number of creative wrappers deactivated: %s\n", $result->numChanges);
// relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the ContentService. $contentService = $user->GetService('ContentService', 'v201408'); // Get the NetworkService. $networkService = $user->GetService('NetworkService', 'v201408'); // Get the CustomTargetingService. $customTargetingService = $user->GetService('CustomTargetingService', 'v201408'); // Get content browse custom targeting key ID. $network = $networkService->getCurrentNetwork(); $contentBrowseCustomTargetingKeyId = $network->contentBrowseCustomTargetingKeyId; // Create a statement to select the categories matching the name comedy. $categoryFilterStatement = new Statement("WHERE customTargetingKeyId = :contentBrowseCustomTargetingKeyId " . "and name = :category LIMIT 1"); $categoryFilterStatement->values = MapUtils::GetMapEntries(array('contentBrowseCustomTargetingKeyId' => new NumberValue($contentBrowseCustomTargetingKeyId), 'category' => new TextValue('comedy'))); // Get categories matching the filter statement. $customTargetingValuePage = $customTargetingService->getCustomTargetingValuesByStatement($categoryFilterStatement); // Get the custom targeting value ID for the comedy category. $categoryCustomTargetingValueId = $customTargetingValuePage->results[0]->id; // Create a statement to get all active content. $filterStatement = new Statement("WHERE status = 'ACTIVE' LIMIT 500"); // Get content by statement. $page = $contentService->getContentByStatementAndCustomTargetingValue($filterStatement, $categoryCustomTargetingValueId); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $content) { printf("%d) Content with ID '%s', name '%s', and status '%s' was found.\n", $i, $content->id, $content->name, $content->status); $i++; }
// relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the ContactService. $contactService = $user->GetService('ContactService', 'v201306'); // Statement parts to help build a statement to only select contacts that // aren't invited yet. $pqlTemplate = 'WHERE status = :status ORDER BY id LIMIT %d OFFSET %d'; $STATUS = 'UNINVITED'; $SUGGESTED_PAGE_LIMIT = 500; $offset = 0; $page = new ContactPage(); do { // Get contacts by statement. $vars = MapUtils::GetMapEntries(array('status' => new TextValue($STATUS))); $page = $contactService->getContactsByStatement(new Statement(sprintf($pqlTemplate, $SUGGESTED_PAGE_LIMIT, $offset), $vars)); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $contact) { printf("%d) Contact with ID \"%d\" and name \"%s\" was found.\n", $i++, $contact->id, $contact->name); } } $offset += $SUGGESTED_PAGE_LIMIT; } while ($offset < $page->totalResultSetSize); printf("Number of results found: %d\n", $page->totalResultSetSize); } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e); } catch (ValidationException $e) { ExampleUtils::CheckForOAuth2Errors($e);
/** * Gets the {@link Statement} representing the state of this statement * builder. * * @return Statement the {@link Statement} */ public function ToStatement() { $statement = new Statement(); $statement->query = $this->buildQuery(); $statement->values = MapUtils::GetMapEntries($this->GetBindVariableMap()); return $statement; }
// $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CustomFieldService. $customFieldService = $user->GetService('CustomFieldService', 'v201311'); // Create bind variables. $vars = MapUtils::GetMapEntries(array('entityType' => new TextValue("LINE_ITEM"), 'isActive' => new BooleanValue("TRUE"))); // Create statement text to select only active custom fields that apply // to line items. $filterStatementText = "WHERE entityType = :entityType and isActive = :isActive"; $offset = 0; do { // Create statement to page through results. $filterStatement = new Statement($filterStatementText . " LIMIT 500 OFFSET " . $offset, $vars); // Get custom fields by statement. $page = $customFieldService->getCustomFieldsByStatement($filterStatement); // Display results. $customFieldIds = array(); if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $customField) { print $i . ') Custom field with ID "' . $customField->id . '" and name "' . $customField->name . "\" will be deactivated.\n";
// $path = '/path/to/dfp_api_php_lib/src'; $path = dirname(__FILE__) . '/../../../../src'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the CreativeService. $creativeService = $user->GetService('CreativeService', 'v201208'); // Create bind variables. $vars = MapUtils::GetMapEntries(array('creativeType' => new TextValue('ImageCreative'))); // Create a statement to only select image creatives. $filterStatement = new Statement("WHERE creativeType = :creativeType LIMIT 500", $vars); // Get creatives by statement. $page = $creativeService->getCreativesByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $creative) { print $i . ') Creative with ID "' . $creative->id . '", name "' . $creative->name . '", and type "' . $creative->CreativeType . "\" was found.\n"; $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e);
require_once 'Google/Api/Ads/Dfp/Lib/DfpUser.php'; require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php'; try { // Get DfpUser from credentials in "../auth.ini" // relative to the DfpUser.php file's directory. $user = new DfpUser(); // Log SOAP XML request and response. $user->LogDefaults(); // Get the UserTeamAssociationService. $userTeamAssociationService = $user->GetService('UserTeamAssociationService', 'v201311'); // Get the UserService. $userService = $user->GetService("UserService", "v201311"); // Get the current user. $currentUserId = $userService->getCurrentUser()->id; // Create bind variables. $vars = MapUtils::GetMapEntries(array('userId' => new NumberValue($currentUserId))); // Create filter text to select user team associations by the user ID. $filterStatement = new Statement("WHERE userId = :userId LIMIT 500", $vars); // Get user team associations by statement. $page = $userTeamAssociationService->getUserTeamAssociationsByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $uta) { print $i . ') User team association between user with ID "' . $uta->userId . '" and team with ID "' . $uta->teamId . "\" was found.\n"; $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e);