/** * Test getting map entries from a map, using a named map entries class. * @covers MapUtils::GetMapEntries */ public function testGetMapEntries_NamedEntries() { $map = array('foo' => 'bar'); $result = MapUtils::GetMapEntries($map, 'TestMapEntry'); $this->assertEquals(1, sizeof($result)); $this->assertTrue($result[0] instanceof TestMapEntry); $this->assertEquals('foo', $result[0]->key); $this->assertEquals('bar', $result[0]->value); }
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; }
// 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 = 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 SuggestedAdUnitService. $suggestedAdUnitService = $user->GetService('SuggestedAdUnitService', 'v201208'); // Create a statement to only select suggested ad units with more than 50 // requests. $filterStatement = new Statement("WHERE numRequests > :numRequests LIMIT 500", MapUtils::GetMapEntries(array('numRequests' => new NumberValue(50)))); // Get ad units by statement. $page = $suggestedAdUnitService->getSuggestedAdUnitsByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $suggestedAdUnit) { printf("%d) Suggested ad unit with ID '%s' and number of requests '%d' " . "was found.\n", $i, $suggestedAdUnit->id, $suggestedAdUnit->numRequests); $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e); } catch (ValidationException $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);
$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) {
// 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++; }
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));
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.
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', 'v201208'); // Set the name of the custom targeting key to delete. $keyName = 'INSERT_CUSTOM_TARGETING_KEY_NAME_HERE'; // Create statement text to only select custom targeting key by the given // name. $filterStatementText = 'WHERE name = :name'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('name' => new TextValue($keyName))); $offset = 0; $keyIds = array(); do { // Create statement to page through results. $filterStatement = new Statement($filterStatementText . ' LIMIT 500 OFFSET ' . $offset, $vars); // Get custom targeting keys by statement. $page = $customTargetingService->getCustomTargetingKeysByStatement($filterStatement); if (isset($page->results)) { foreach ($page->results as $customTargetingKey) { $keyIds[] = $customTargetingKey->id; } } $offset += 500; } while ($offset < $page->totalResultSetSize); printf("Number of custom targeting keys to be deleted: %d\n", sizeof($keyIds));
$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 LineItemService. $lineItemService = $user->GetLineItemService('v201104'); // Set the ID of the order to get line items from. $orderId = (double) 'INSERT_ORDER_ID_HERE'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('orderId' => new NumberValue($orderId))); // Create statement text to select approved line items from a given order. $filterStatementText = "WHERE orderId = :orderId AND status = 'NEEDS_CREATIVES'"; $offset = 0; do { // Create statement to page through results. $filterStatement = new Statement($filterStatementText . " LIMIT 500 OFFSET " . $offset, $vars); // Get line items by statement. $page = $lineItemService->getLineItemsByStatement($filterStatement); // Display results. $lineItemIds = array(); if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $lineItem) { // Archived line items cannot be activated. if (!$lineItem->isArchived) {
$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 AudienceSegmentService. $audienceSegmentService = $user->GetService('AudienceSegmentService', 'v201405'); $audienceSegmentId = 'INSERT_AUDIENCE_SEGMENT_ID_HERE'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('type' => new TextValue('FIRST_PARTY'), 'audienceSegmentId' => new NumberValue($audienceSegmentId))); // Statement parts to help build a statement to select specified first party // audience segment. $pqlTemplate = "WHERE id IN (:audienceSegmentId) AND type = :type ORDER BY " . "id LIMIT %d OFFSET %d"; $SUGGESTED_PAGE_LIMIT = 500; $offset = 0; $page = new AudienceSegmentPage(); do { // Get audience segments by statement. $page = $audienceSegmentService->getAudienceSegmentsByStatement(new Statement(sprintf($pqlTemplate, $SUGGESTED_PAGE_LIMIT, $offset), $vars)); // Display results. $audienceSegmentIds = array(); if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $audienceSegment) { printf("%d) Audience segment with ID \"%d\" and name \"%s\" will be " . "populated.\n", $i++, $audienceSegment->id, $audienceSegment->name);
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 InventoryService. $inventoryService = $user->GetService('InventoryService', 'v201403'); // Get the NetworkService. $networkService = $user->GetService('NetworkService', 'v201403'); // Get the effective root ad unit's ID. $network = $networkService->getCurrentNetwork(); $effectiveRootAdUnitId = $network->effectiveRootAdUnitId; // Create a statement to select the children of the effective root ad unit. $filterStatement = new Statement("WHERE parentId = :id LIMIT 500", MapUtils::GetMapEntries(array('id' => new NumberValue($effectiveRootAdUnitId)))); // Get ad units by statement. $page = $inventoryService->getAdUnitsByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $adUnit) { print $i . ') Ad unit with ID "' . $adUnit->id . '", name "' . $adUnit->name . '", and status "' . $adUnit->status . "\" was found.\n"; $i++; } } print 'Number of results found: ' . $page->totalResultSetSize . "\n"; } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e); } catch (ValidationException $e) { ExampleUtils::CheckForOAuth2Errors($e);
// 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 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 InventoryService. $inventoryService = $user->GetService('InventoryService', 'v201403'); // Create bind variables. $vars = MapUtils::GetMapEntries(array('targetPlatform' => new TextValue('WEB'))); // Create a statement to only select web ad units sizes. $filterStatement = new Statement("WHERE targetPlatform = :targetPlatform", $vars); // Get all ad unit sizes by statement. $adUnitSizes = $inventoryService->getAdUnitSizesByStatement($filterStatement); // Display results. $i = 0; foreach ($adUnitSizes as $adUnitSize) { printf("%d) Web ad unit size of dimensions %s was found.\n", $i, $adUnitSize->fullDisplayString); $i++; } printf("Number of ad unit sizes found: %d\n", count($adUnitSizes)); } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e); } catch (ValidationException $e) { ExampleUtils::CheckForOAuth2Errors($e);
require_once 'Google/Api/Ads/Common/Util/MapUtils.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 LineItemService. $lineItemService = $user->GetService('LineItemService', 'v201311'); // Set the ID of the order to get line items from. $orderId = 'INSERT_ORDER_ID_HERE'; // Calculate time from three days ago. $threeDaysAgo = date(DateTimeUtils::$DFP_DATE_TIME_STRING_FORMAT, strtotime('-3 day')); // Create bind variables. $vars = MapUtils::GetMapEntries(array('orderId' => new NumberValue($orderId), 'threeDaysAgo' => new TextValue($threeDaysAgo))); // Create statement object to only select line items belonging to the order // and have been modified in the last 3 days. $filterStatement = new Statement("WHERE orderId = :orderId " . "AND lastModifiedDateTime >= :threeDaysAgo " . "LIMIT 500", $vars); // Get line items by statement. $page = $lineItemService->getLineItemsByStatement($filterStatement); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $lineItem) { // Format lastModifiedDateTime for printing. $lastModifiedDateTime = DateTimeUtils::GetDateTime($lineItem->lastModifiedDateTime); $lastModifiedDateTimeText = $lastModifiedDateTime->format(DateTimeUtils::$DFP_DATE_TIME_STRING_FORMAT); print $i . ') Line item with ID "' . $lineItem->id . '", belonging to order ID "' . $lineItem->orderId . '", with name "' . $lineItem->name . '", and last modified ' . $lastModifiedDateTimeText . " was found.\n"; $i++; }
$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 AudienceSegmentService. $audienceSegmentService = $user->GetService('AudienceSegmentService', 'v201405'); // Set the ID of the first party audience segment to update. $audienceSegmentId = 'INSERT_AUDIENCE_SEGMENT_ID_HERE'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('audienceSegmentId' => new NumberValue($audienceSegmentId))); // Create statement text to select the audience segment to update. $filterStatementText = "WHERE id = :audienceSegmentId LIMIT 1"; // Get the audience segment. $audienceSegment = $audienceSegmentService->getAudienceSegmentsByStatement(new Statement($filterStatementText, $vars))->results[0]; // Update the member expiration days. $audienceSegment->membershipExpirationDays = 180; // Update the audience segment on the server. $audienceSegments = $audienceSegmentService->updateAudienceSegments(array($audienceSegment)); // Display results. if (isset($audienceSegments)) { foreach ($audienceSegments as $updatedAudienceSegment) { printf("Audience segment with ID \"%d\" and name \"%s\" was updated.\n", $updatedAudienceSegment->id, $updatedAudienceSegment->name); } } else { printf("No audience segments were updated.\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 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());
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.
// $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);
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++;
// $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);
// $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) {
/** * 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; }
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
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 ActivityGroupService. $activityGroupService = $user->GetService('ActivityGroupService', 'v201405'); // Set the ID of the activity group and the company to update it with. $activityGroupId = 'INSERT_ACTIVITY_GROUP_ID_HERE'; $advertiserCompanyId = 'INSERT_ADVERTISER_COMPANY_ID_HERE'; // Create a statement to select a single activity group by ID. $vars = MapUtils::GetMapEntries(array('id' => new NumberValue($activityGroupId))); $filterStatement = new Statement("WHERE id = :id ORDER BY id ASC LIMIT 1", $vars); // Get the activity group. $page = $activityGroupService->getActivityGroupsByStatement($filterStatement); $activityGroup = $page->results[0]; // Update the companies. $activityGroup->companyIds[] = $advertiserCompanyId; // Update the activity group on the server. $activityGroups = $activityGroupService->updateActivityGroups(array($activityGroup)); // Display results. foreach ($activityGroups as $updatedActivityGroup) { printf("Activity group with ID '%d' and name '%s' was updated.\n", $updatedActivityGroup->id, $updatedActivityGroup->name); } } catch (OAuth2Exception $e) { ExampleUtils::CheckForOAuth2Errors($e); } catch (ValidationException $e) {
// 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);
require_once 'Google/Api/Ads/Common/Util/MapUtils.php'; 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 SuggestedAdUnitService. $suggestedAdUnitService = $user->GetService('SuggestedAdUnitService', 'v201408'); // Set the number of requests for suggested ad units greater than which to // approve. $numRequests = 'INSERT_NUMBER_OF_REQUESTS_HERE'; // Create bind variables. $vars = MapUtils::GetMapEntries(array('numRequests' => new NumberValue($numRequests))); // Statement parts to help build a statement to select suggested ad units that // are highly requested. $pqlTemplate = "WHERE numRequests >= :numRequests ORDER BY id LIMIT %d " . "OFFSET %d"; $SUGGESTED_PAGE_LIMIT = 500; $offset = 0; $page = null; $suggestedAdUnitIds = array(); do { // Get suggested ad units by statement. $page = $suggestedAdUnitService->getSuggestedAdUnitsByStatement(new Statement(sprintf($pqlTemplate, $SUGGESTED_PAGE_LIMIT, $offset), $vars)); // Display results. if (isset($page->results)) { $i = $page->startIndex; foreach ($page->results as $suggestedAdUnit) { printf("%d) Suggested ad unit with ID '%s' and number of requests '%d' " . "will be approved.\n", $i++, $suggestedAdUnit->id);
// $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);
// $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";