GetService() public method

Gets the service by its service name.
public GetService ( string $serviceName, string $version = null, string $server = null, SoapClientFactory $serviceFactory = null ) : SoapClient
$serviceName string the service name
$version string the version of the service to get. If null, then the default version will be used
$server string the server to make the request to. If null, then the default server will be used
$serviceFactory SoapClientFactory the factory to create the client. If null, then the built-in SOAP client factory will be used
return SoapClient the instantiated service
/**
 * Run an example using the $user object.
 * @param string $user the user that contains the client ID and secret
 */
function RunExample(DfpUser $user)
{
    // Get the NetworkService.
    $networkService = $user->GetService('NetworkService');
    // Gets the current network.
    $network = $networkService->getCurrentNetwork();
    printf("Current network has network code %d and display name \"%s\".\n", $network->networkCode, $network->displayName);
}
/**
 * Finds the root ad unit for the user.
 * @param DfpUser $user the user to get the root ad unit for
 * @return the ad unit representing the root ad unit or <var>NULL</var> if one
 *     is not found.
 * @access private
 */
function FindRootAdUnit(DfpUser $user)
{
    // Get the InventoryService.
    $inventoryService = $user->GetService('InventoryService', 'v201208');
    // Create a statement to only select image creatives.
    $filterStatement = new Statement("WHERE parentId IS NULL LIMIT 1");
    // Get ad units by statement.
    $page = $inventoryService->getAdUnitsByStatement($filterStatement);
    if (isset($page->results)) {
        return $page->results[0];
    } else {
        return NULL;
    }
}
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 CustomFieldService.
    $customFieldService = $user->GetService('CustomFieldService', 'v201211');
    // Set the ID of the drop-down custom field to create options for.
    $customFieldId = "INSERT_DROP_DOWN_CUSTOM_FIELD_ID_HERE";
    // Create custom field options.
    $customFieldOption1 = new CustomFieldOption();
    $customFieldOption1->displayName = 'Approved';
    $customFieldOption1->customFieldId = $customFieldId;
    $customFieldOption2 = new CustomFieldOption();
    $customFieldOption2->displayName = 'Unapproved';
    $customFieldOption2->customFieldId = $customFieldId;
    // Create the custom targeting keys on the server.
    $customFieldOptions = $customFieldService->createCustomFieldOptions(array($customFieldOption1, $customFieldOption2));
    // Display results.
    if (isset($customFieldOptions)) {
        foreach ($customFieldOptions as $customFieldOption) {
            printf("A custom field option with ID '%s' and name '%s' was created.\n", $customFieldOption->id, $customFieldOption->displayName);
Exemplo n.º 4
0
 */
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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';
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', 'v201108');
    // Create a statement to get all ad units.
    $filterStatement = new Statement("LIMIT 500");
    // Get ad units by statement.
    $page = $inventoryService->getAdUnitsByStatement($filterStatement);
    if (isset($page->results)) {
        $adUnits = $page->results;
        // Update each local ad unit object by enabling AdSense.
        foreach ($adUnits as $adUnit) {
            $adUnit->inheritedAdSenseSettings->value->adSenseEnabled = TRUE;
        }
        // Update the ad units on the server.
        $adUnits = $inventoryService->updateAdUnits($adUnits);
        // Display results.
        if (isset($adUnits)) {
            foreach ($adUnits as $adUnit) {
// You can set the include path to src directory or reference
// 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';
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', 'v201308');
    // Get the LineItemService.
    $lineItemService = $user->GetService('LineItemService', 'v201308');
    // 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";
    // Get the line item.
    $lineItem = $lineItemService->getLineItem($lineItemId);
    // Create custom field values.
    $customFieldValues = array();
    $customFieldValue = new CustomFieldValue();
    $customFieldValue->customFieldId = $customFieldId;
    $customFieldValue->value = new TextValue("Custom field value");
    $customFieldValues[] = $customFieldValue;
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 LabelService.
    $labelService = $user->GetService('LabelService', 'v201405');
    // Create statement text to get all active labels.
    $filterStatementText = "WHERE isActive = true";
    $offset = 0;
    do {
        // Create statement to page through results.
        $filterStatement = new Statement($filterStatementText . " LIMIT 500 OFFSET " . $offset);
        // Get labels by statement.
        $page = $labelService->getLabelsByStatement($filterStatement);
        // Display results.
        $labelIds = array();
        if (isset($page->results)) {
            foreach ($page->results as $label) {
                printf("A label with ID '%s' and name '%s' will be deactivated.\n", $label->id, $label->name);
                $labelIds[] = $label->id;
            }
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 ContactService.
    $contactService = $user->GetService('ContactService', 'v201311');
    // Set the ID of the advertiser company this contact is associated with.
    $advertiserCompanyId = 'INSERT_ADVERTISER_COMPANY_ID_HERE';
    // Set the ID of the agency company this contact is associated with.
    $agencyCompanyId = 'INSERT_AGENCY_COMPANY_ID_HERE';
    // Create an advertiser contact.
    $advertiserContact = new Contact();
    $advertiserContact->name = sprintf('Mr. Advertiser #%s', uniqid());
    $advertiserContact->email = '*****@*****.**';
    $advertiserContact->companyId = $advertiserCompanyId;
    // Create an agency contact.
    $agencyContact = new Contact();
    $agencyContact->name = sprintf('Ms. Agency #%s', uniqid());
    $agencyContact->email = '*****@*****.**';
    $agencyContact->companyId = $agencyCompanyId;
    // Create the contacts on the server.
 * @copyright  2012, Google Inc. All Rights Reserved.
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License,
 *             Version 2.0
 * @author     Eric Koleda
 */
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 UserService.
    $userService = $user->GetService('UserService', 'v201211');
    // Get the current user.
    $usr = $userService->getCurrentUser();
    printf("User with ID '%s', email '%s', and role '%s' was found.\n", $usr->id, $usr->email, $usr->roleName);
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
    print $e->getMessage() . "\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 'Google/Api/Ads/Dfp/Util/v201502/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the ID of the company to update.
$companyId = 'INSERT_COMPANY_ID_HERE';
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', 'v201502');
    // Create a statement to select a single company by ID.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Where('id = :id')->OrderBy('id ASC')->Limit(1)->WithBindVariableValue('id', $companyId);
    // Get the company.
    $page = $companyService->getCompaniesByStatement($statementBuilder->ToStatement());
    $company = $page->results[0];
    // Update the comment.
    $company->comment = sprintf('%s - updated.', $company->comment);
    // Update the company on the server.
    $companies = $companyService->updateCompanies(array($company));
    foreach ($companies as $updatedCompany) {
        printf("Company with ID %d, name '%s', and comment '%s' was updated.\n", $updatedCompany->id, $updatedCompany->name, $updatedCompany->comment);
    }
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
// You can set the include path to src directory or reference
// 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/Dfp/Util/v201511/StatementBuilder.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 CreativeSetService.
    $creativeSetService = $user->GetService('CreativeSetService', 'v201511');
    // Create a statement to select all creative sets.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get creative sets by statement.
        $page = $creativeSetService->getCreativeSetsByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $creativeSet) {
                printf("%d) Creative set with ID %d, and name '%s' was found.\n", $i++, $creativeSet->id, $creativeSet->name);
            }
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 SuggestedAdUnitService.
    $suggestedAdUnitService = $user->GetService('SuggestedAdUnitService', 'v201405');
    // Set defaults for page and statement.
    $page = new SuggestedAdUnitPage();
    $filterStatement = new Statement();
    $offset = 0;
    do {
        // Create a statement to get all suggested ad units.
        $filterStatement->query = 'LIMIT 500 OFFSET ' . $offset;
        // Get creatives 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++;
// $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/Dfp/Util/v201505/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the ID of the creative wrapper to update.
$creativeWrapperId = 'INSERT_CREATIVE_WRAPPER_ID_HERE';
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->GetService('CreativeWrapperService', 'v201505');
    // Create a statement to select a single creative wrapper by ID.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Where('id = :id')->OrderBy('id ASC')->Limit(1)->WithBindVariableValue('id', $creativeWrapperId);
    // Get the creative wrapper.
    $page = $creativeWrapperService->getCreativeWrappersByStatement($statementBuilder->ToStatement());
    $creativeWrapper = $page->results[0];
    // Update the creative wrapper ordering.
    $creativeWrapper->ordering = 'OUTER';
    // Update the creative wrapper on the server.
    $creativeWrappers = $creativeWrapperService->updateCreativeWrappers(array($creativeWrapper));
    foreach ($creativeWrappers as $updatedCreativeWrapper) {
        printf("Creative wrapper with ID %d, and wrapping order '%s' was " . "updated.\n", $updatedCreativeWrapper->id, $updatedCreativeWrapper->ordering);
    }
} 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 'Google/Api/Ads/Dfp/Util/v201602/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the rate card ID to filter base rates on.
$rateCardId = 'INSERT_RATE_CARD_ID_HERE';
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 BaseRateService.
    $baseRateService = $user->GetService('BaseRateService', 'v201602');
    // Create a statement to select only base rates belonging to a rate card.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Where('rateCardId = :rateCardId')->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)->WithBindVariableValue('rateCardId', $rateCardId);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get base rates by statement.
        $page = $baseRateService->getBaseRatesByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $baseRate) {
                printf("%d) Base rate with ID %d, and type '%s', belonging to rate " . "card ID %d was found.\n", $i++, $baseRate->id, get_class($baseRate), $baseRate->rateCardId);
            }
// 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/Dfp/Util/v201508/Pql.php';
require_once 'Google/Api/Ads/Dfp/Util/v201508/StatementBuilder.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', 'v201508');
    // Create statement to select all line items.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Select('Id, BrowserName, MajorVersion, MinorVersion')->From('Browser')->OrderBy('BrowserName ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Default for result sets.
    $resultSet = null;
    $combinedResultSet = null;
    $i = 0;
    do {
        // Get all browsers.
        $resultSet = $pqlService->select($statementBuilder->ToStatement());
        // Combine result sets with previous ones.
        $combinedResultSet = !isset($combinedResultSet) ? $resultSet : Pql::CombineResultSets($combinedResultSet, $resultSet);
        printf("%d) %d browsers beginning at offset %d were found.\n", $i++, isset($resultSet->rows) ? count($resultSet->rows) : 0, $statementBuilder->GetOffset());
        $statementBuilder->IncreaseOffsetBy(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    } while (isset($resultSet->rows) && count($resultSet->rows) > 0);
Exemplo n.º 15
0
// $path = '/path/to/dfp_api_php_lib/src';
$path = dirname(__FILE__) . '/../../../../lib';
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/v201508/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the ID of the line item to deactivate LICAs for.
$lineItemId = 'INSERT_LINE_ITEM_ID_HERE';
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 LineItemCreativeAssociationService.
    $licaService = $user->GetService('LineItemCreativeAssociationService', 'v201508');
    // Create a statement to select all LICAs for a line item.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Where('lineItemId = :lineItemId')->OrderBy('lineItemId ASC, creativeId ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)->WithBindVariableValue('lineItemId', $lineItemId);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get LICAs by statement.
        $page = $licaService->getLineItemCreativeAssociationsByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $lica) {
                if (isset($lica->creativeSetId)) {
                    printf("%d) LICA with line item ID %d, and creative set ID %d will " . "be deactivated.\n", $i++, $lica->lineItemId, $lica->creativeSetId);
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 AudienceSegmentService.
    $audienceSegmentService = $user->GetService('AudienceSegmentService', 'v201411');
    // Get the NetworkService.
    $networkService = $user->GetService('NetworkService', 'v201411');
    // Set the IDs of the custom criteria to be used in the segment rule.
    $customTargetingKeyId = 'INSERT_CUSTOM_TARGETING_KEY_ID_HERE';
    $customTargetingValueId = 'INSERT_CUSTOM_TARGETING_VALUE_ID_HERE';
    // Get the root ad unit ID used to target the whole site.
    $rootAdUnitId = $networkService->getCurrentNetwork()->effectiveRootAdUnitId;
    // Create inventory targeting to be used in the segment rule.
    $inventoryTargeting = new InventoryTargeting();
    // Create ad unit targeting for the root ad unit (i.e. the whole network).
    $adUnitTargeting = new AdUnitTargeting();
    $adUnitTargeting->adUnitId = $rootAdUnitId;
    $inventoryTargeting->targetedAdUnits = array($adUnitTargeting);
    // Create custom criteria to be used in the segment rule.
    $customCriteria = new CustomCriteria();
// You can set the include path to src directory or reference
// 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/Dfp/Util/v201505/DateTimeUtils.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 ForecastService.
    $forecastService = $user->GetService('ForecastService', 'v201505');
    // Get the NetworkService.
    $networkService = $user->GetService('NetworkService', 'v201505');
    // Get the root ad unit ID used to target the whole site.
    $rootAdUnitId = $networkService->getCurrentNetwork()->effectiveRootAdUnitId;
    // Create inventory targeting.
    $inventoryTargeting = new InventoryTargeting();
    // Create ad unit targeting for the root ad unit.
    $adUnitTargeting = new AdUnitTargeting();
    $adUnitTargeting->adUnitId = $rootAdUnitId;
    $adUnitTargeting->includeDescendants = true;
    $inventoryTargeting->targetedAdUnits = array($adUnitTargeting);
    // Create targeting.
    $targeting = new Targeting();
    $targeting->inventoryTargeting = $inventoryTargeting;
    // Create a line item.
Exemplo n.º 18
0
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 TeamService.
    $teamService = $user->GetService('TeamService', 'v201505');
    // Create an array to store local team objects.
    $teams = array();
    for ($i = 0; $i < 5; $i++) {
        $team = new Team();
        $team->name = 'Team #' . uniqid();
        $team->hasAllCompanies = false;
        $team->hasAllInventory = false;
        $teams[] = $team;
    }
    // Create the teams on the server.
    $teams = $teamService->createTeams($teams);
    // Display results.
    if (isset($teams)) {
        foreach ($teams as $team) {
            print 'A team with ID "' . $team->id . '" and name "' . $team->name . '" was created."' . "\n";
Exemplo n.º 19
0
// You can set the include path to src directory or reference
// 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/Dfp/Util/v201602/StatementBuilder.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 CreativeService.
    $creativeService = $user->GetService('CreativeService', 'v201602');
    // Create a statement to select all creatives.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get creatives by statement.
        $page = $creativeService->getCreativesByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $creative) {
                printf("%d) Creative with ID %d, and name '%s' was found.\n", $i++, $creative->id, $creative->name);
            }
Exemplo n.º 20
0
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// DfpUser.php directly via require_once.
// $path = '/path/to/dfp_api_php_lib/src';
$path = dirname(__FILE__) . '/../../../../lib';
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 ExchangeRateService.
    $exchangeRateService = $user->GetService('ExchangeRateService', 'v201411');
    // Create an exchange rate.
    $exchangeRate = new ExchangeRate();
    // Set the currency code.
    $exchangeRate->currencyCode = 'AUD';
    // Set the direction of the conversion (from the network currency).
    $exchangeRate->direction = 'FROM_NETWORK';
    // Set the conversion value as 1.5 (this value is multiplied by
    // 10,000,000,000)
    $exchangeRate->exchangeRate = 15000000000;
    // Do not refresh exchange rate from Google data. Update manually only.
    $exchangeRate->refreshRate = 'FIXED';
    // Create the exchange rate on the server.
    $exchangeRates = $exchangeRateService->createExchangeRates(array($exchangeRate));
    foreach ($exchangeRates as $createdExchangeRate) {
        printf("An exchange rate with ID %d, currency code '%s', direction '%s', " . "and exchange rate %.2f was created.\n", $createdExchangeRate->id, $createdExchangeRate->currencyCode, $createdExchangeRate->direction, $createdExchangeRate->exchangeRate / 10000000000);
// $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/Dfp/Util/v201608/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the ID of the custom targeting key to update.
$customTargetingKeyId = 'INSERT_CUSTOM_TARGETING_KEY_ID_HERE';
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', 'v201608');
    // Create a statement to select a single custom targeting key by ID.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Where('id = :id')->OrderBy('id ASC')->Limit(1)->WithBindVariableValue('id', $customTargetingKeyId);
    // Default for total result set size.
    $totalResultSetSize = 0;
    // Get the custom targeting key.
    $page = $customTargetingService->getCustomTargetingKeysByStatement($statementBuilder->ToStatement());
    $customTargetingKey = $page->results[0];
    // Update the custom targeting key's display name.
    $customTargetingKey->displayName = 'New custom targeting key display name.';
    // Update the custom targeting key on the server.
    $customTargetingKeys = $customTargetingService->updateCustomTargetingKeys(array($customTargetingKey));
    foreach ($customTargetingKeys as $updatedCustomTargetingKey) {
        printf("Custom targeting key with ID %d, name '%s', and display name '%s' " . "was updated.\n", $updatedCustomTargetingKey->id, $updatedCustomTargetingKey->name, $updatedCustomTargetingKey->displayName);
    }
// $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/Dfp/Util/v201602/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the ID of the proposal to submit for approval.
$proposalId = 'INSERT_PROPOSAL_ID_HERE';
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 ProposalService.
    $proposalService = $user->GetService('ProposalService', 'v201602');
    // Create a statement to select a single proposal by ID.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Where('id = :id')->OrderBy('id ASC')->Limit(1)->WithBindVariableValue('id', $proposalId);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get proposals by statement.
        $page = $proposalService->getProposalsByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $proposal) {
                printf("%d) Proposal with ID %d and name '%s' will be submitted for " . "approval.\n", $i++, $proposal->id, $proposal->name);
            }
// $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/Dfp/Util/v201602/StatementBuilder.php';
require_once dirname(__FILE__) . '/../../../Common/ExampleUtils.php';
// Set the ID of the reconciliation report to retrieve line item reports for.
$reconciliationReportId = 'INSERT_RECONCILIATION_REPORT_ID_HERE';
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 ReconciliationLineItemReportService.
    $reconciliationLineItemReportService = $user->GetService('ReconciliationLineItemReportService', 'v201602');
    // Create a statement to select reconciliation line item reports for DFP line
    // items.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->Where('reconciliationReportId = :reconciliationReportId ' . 'AND lineItemId != :lineItemId')->OrderBy('lineItemId ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT)->WithBindVariableValue('reconciliationReportId', $reconciliationReportId)->WithBindVariableValue('lineItemId', 0);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get reconciliation line item reports by statement.
        $page = $reconciliationLineItemReportService->getReconciliationLineItemReportsByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $reconciliationLineItemReport) {
                printf("%d) Reconciliation line item report with ID %d for line item ID " . "%d was found, with reconciliation source '%s' and " . "reconciled volume '%d'.\n", $i++, $reconciliationLineItemReport->id, $reconciliationLineItemReport->lineItemId, $reconciliationLineItemReport->reconciliationSource, $reconciliationLineItemReport->reconciledVolume);
 * @copyright  2012, Google Inc. All Rights Reserved.
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License,
 *             Version 2.0
 * @author     Eric Koleda
 */
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 NetworkService.
    $networkService = $user->GetService('NetworkService', 'v201211');
    // Get the current network.
    $network = $networkService->getCurrentNetwork();
    print 'Current network has network code "' . $network->networkCode . '" and display name "' . $network->displayName . "\".\n";
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
    print $e->getMessage() . "\n";
}
Exemplo n.º 25
0
// You can set the include path to src directory or reference
// 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/Dfp/Util/v201408/StatementBuilder.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 ContentService.
    $contentService = $user->GetService('ContentService', 'v201408');
    // Create a statement to select all content.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get content by statement.
        $page = $contentService->getContentByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $content) {
                printf("%d) Content with ID %d, name '%s', and status %s was found.\n", $i++, $content->id, $content->name, $content->status);
            }
Exemplo n.º 26
0
 * @category   WebServices
 * @copyright  2013, Google Inc. All Rights Reserved.
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License,
 *             Version 2.0
 */
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 UserService.
    $userService = $user->GetService('UserService', 'v201605');
    // Get the current user.
    $usr = $userService->getCurrentUser();
    printf("User with ID '%s', email '%s', and role '%s' was found.\n", $usr->id, $usr->email, $usr->roleName);
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
    print $e->getMessage() . "\n";
}
 * @copyright  2013, Google Inc. All Rights Reserved.
 * @license    http://www.apache.org/licenses/LICENSE-2.0 Apache License,
 *             Version 2.0
 * @author     Eric Koleda
 */
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 UserService.
    $userService = $user->GetService('UserService', 'v201302');
    // Get the current user.
    $usr = $userService->getCurrentUser();
    printf("User with ID '%s', email '%s', and role '%s' was found.\n", $usr->id, $usr->email, $usr->roleName);
} catch (OAuth2Exception $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (ValidationException $e) {
    ExampleUtils::CheckForOAuth2Errors($e);
} catch (Exception $e) {
    print $e->getMessage() . "\n";
}
Exemplo n.º 28
0
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// DfpUser.php directly via require_once.
// $path = '/path/to/dfp_api_php_lib/src';
$path = dirname(__FILE__) . '/../../../../lib';
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 ActivityService.
    $activityService = $user->GetService('ActivityService', 'v201502');
    // Set the ID of the activity group this activity is associated with.
    $activityGroupId = 'INSERT_ACTIVITY_GROUP_ID_HERE';
    // Create a daily visits activity.
    $dailyVisitsActivity = new Activity();
    $dailyVisitsActivity->name = sprintf('Activity #%s', uniqid());
    $dailyVisitsActivity->activityGroupId = $activityGroupId;
    $dailyVisitsActivity->type = 'DAILY_VISITS';
    // Create a custom activity.
    $customActivity = new Activity();
    $customActivity->name = sprintf('Activity #%s', uniqid());
    $customActivity->activityGroupId = $activityGroupId;
    $customActivity->type = 'CUSTOM';
    // Create the activities on the server.
    $activities = $activityService->createActivities(array($dailyVisitsActivity, $customActivity));
    // Display results.
error_reporting(E_STRICT | E_ALL);
// You can set the include path to src directory or reference
// 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 TeamService.
    $teamService = $user->GetService('TeamService', 'v201408');
    // Set defaults for page and statement.
    $page = new TeamPage();
    $filterStatement = new Statement();
    $offset = 0;
    do {
        // Create a statement to get all teams.
        $filterStatement->query = 'LIMIT 500 OFFSET ' . $offset;
        // Get teams by statement.
        $page = $teamService->getTeamsByStatement($filterStatement);
        // Display results.
        if (isset($page->results)) {
            $i = $page->startIndex;
            foreach ($page->results as $team) {
                print $i . ') Team with ID "' . $team->id . '" and name "' . $team->name . "\" was found.\n";
                $i++;
// You can set the include path to src directory or reference
// 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/Dfp/Util/v201502/StatementBuilder.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 OrderService.
    $orderService = $user->GetService('OrderService', 'v201502');
    // Create a statement to select all orders.
    $statementBuilder = new StatementBuilder();
    $statementBuilder->OrderBy('id ASC')->Limit(StatementBuilder::SUGGESTED_PAGE_LIMIT);
    // Default for total result set size.
    $totalResultSetSize = 0;
    do {
        // Get orders by statement.
        $page = $orderService->getOrdersByStatement($statementBuilder->ToStatement());
        // Display results.
        if (isset($page->results)) {
            $totalResultSetSize = $page->totalResultSetSize;
            $i = $page->startIndex;
            foreach ($page->results as $order) {
                printf("%d) Order with ID %d, name '%s', and advertiser ID %d was " . "found.\n", $i++, $order->id, $order->name, $order->advertiserId);
            }