Target Devices in PHP

The following example shows how to target specific devices and operating systems using the following Campaign Management service operations.

This example has been developed and run within the environment described in Getting Started Using PHP with Bing Ads Services.

To download the PHP classes included in the sample, see PHP Production Classes for Bing Ads API.

System_CLiX_note Note

This example uses the UserName and Password elements for authentication. For Managing User Authentication with OAuth, replace the UserName and Password elements with the AuthenticationToken, which is your OAuth access token.

<?php

// You must pass the URL of the Campaign Management WSDL.

// Command line usage:
// php.exe DeviceTargeting wsdl
//

// Disable WSDL caching.

ini_set("soap.wsdl_cache_enabled", "0");
ini_set("soap.wsdl_cache_ttl", "0");

// API credentials.

$username = "<usernamegoeshere>";
$password = "<passwordgoeshere";
$token = "<devtokengoeshere>";

// Advertiser's account ID and customer ID.

$accountId = <accountidgoeshere>;
$customerId = <customeridgoeshere>;

// The ID of the campaign that you want to target to specific devices.
// The campaign must already be associated with a target.

$campaignId = '<campaignidgoeshere>';

// Campaign Management WSDL passed as argument

$wsdl = $argv[1];

$targets = null;

try
{
    $proxy = new ClientProxy($username, $password, $token, $accountId, $customerId, $wsdl);

    $targets = GetCampaignTargets($campaignId, $proxy);

    if (null == $targets->Target[0])
    {
        printf("Campaign %s is not associated with a target.\n", $campaignId);
    }
    else
    {
        // Indexing targets array because a campaign can be associated
        // with only one target object.

        PrintDeviceTargets($targets->Target[0]->Id, $proxy);
        TargetDevices($targets->Target[0]->Id, $proxy);
        PrintDeviceTargets($targets->Target[0]->Id, $proxy);
        RemoveDeviceTarget($targets->Target[0]->Id, $proxy);
        PrintDeviceTargets($targets->Target[0]->Id, $proxy);
    }
}
catch (SoapFault $e)
{
    print $e->getMessage()."\n\n";
}
catch (Exception $e)
{
    if ($e->getPrevious())
    {
        ; // Ignore fault exceptions that we already caught.
    }
    else
    {
        print $e->getCode()." ".$e->getMessage()."\n\n";
        print $e->getTraceAsString()."\n\n";
    }
}

// Gets the target associated with the specified campaign. Because most
// campaigns target a location, this example assumes that the campaign is
// already associated with a target object.

// If the campaign is not associated with a target, you would need to create a
// Target object that sets the Device element to computers or smartphones
// (it doesn't matter which one). After calling the AddTargetsToLibrary
// operation to add the target to the target library, you would call the
// SetTargetToCampaign operation to associate the target with the campaign.

function GetCampaignTargets($campaignId, $proxy)
{
    $request = new GetTargetsByCampaignIdsRequest();
    $response = null;  // GetTargetsByCampaignIdsResponse

    // Set the request information.

    $request->CampaignIds = array( $campaignId );

    try
    {
        printf("Getting target associated with campaign %s.\n", $campaignId);

        $response = $proxy->GetService()->GetTargetsByCampaignIds($request);
    }
    catch (SoapFault $e)
    {
        // Log this fault.

        print "GetTargetsByCampaignIds failed with the following faults:\n";

        if (isset($e->detail->AdApiFaultDetail))
        {
            print "AdApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->AdApiFaultDetail->TrackingId ."\n";

            // Process any system errors.

            $errors = is_array($e->detail->AdApiFaultDetail->Errors->AdApiError)
                    ? $e->detail->AdApiFaultDetail->Errors->AdApiError
                    : array('AdApiError' => $e->detail->AdApiFaultDetail->Errors->AdApiError);

            foreach ($errors as $error)
            {
                if (105 == $error->Code) //  InvalidCredentials
                {
                    print "The specified credentials are not valid or the account is inactive.\n";
                }
                else
                {
                    printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                        $error->ErrorCode, $error->Code, $error->Message, $error->Detail);
                }
            }
        }
        elseif (isset($e->detail->ApiFaultDetail))
        {
            print "ApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->ApiFaultDetail->TrackingId."\n";

            // Process any operation errors.

            if (!empty($e->detail->ApiFaultDetail->OperationErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->OperationErrors->OperationError)
                        ? $e->detail->ApiFaultDetail->OperationErrors->OperationError
                        : array('OperationError' => $e->detail->ApiFaultDetail->OperationErrors->OperationError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        case 106: //  UserIsNotAuthorized
                            print("The user is not authorized to call this operation.\n");
                            break;

                        case 1029: //  CampaignServiceCustomerIdHasToBeSpecified
                            print("The CustomerId header element cannot be null or empty.\n");
                            break;

                        case 1030: //  CampaignServiceAccountIdHasToBeSpecified
                            print("The CustomerAccountId header element " .
                                "cannot be null or empty.\n");
                            break;

                        default:
                            printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Message, $error->Details);
                            break;
                    }
                }
            }

            // Process any batch errors.

            if (!empty($e->detail->ApiFaultDetail->BatchErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->BatchErrors->BatchError)
                        ? $e->detail->ApiFaultDetail->BatchErrors->BatchError
                        : array('BatchError' => $e->detail->ApiFaultDetail->BatchErrors->BatchError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        default:
                            printf("Error code: %s (%d)\nIndex: %d\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Index, $error->Message, $error->Details);
                            break;
                    }
                }
            }
        }
        else
        {
            print $e->getCode()." ".$e->getMessage()."\n\n";

            // Output the last request/response.

            print "\nLast SOAP request/response:\n";
            print $proxy->GetWsdl()."\n";
            print $proxy->GetService()->__getLastRequest()."\n";
            print $proxy->GetService()->__getLastResponse()."\n";
        }

        throw new Exception("", 0, $e);
    }

    return $response->Targets;
}


// To target devices or operating systems, call the UpdateDeviceOSTargets
// operation. Because the operation overwrites the current list
// of devices being targeted, you must specify all devices to target.

// This example targets only smartphones running the Windows operation system.
// To target all operating systems of a device type, set OSName to null.
// If DeviceName is set to Computers, OSName must be set to null.

function TargetDevices($targetId, $proxy)
{
    $request = new UpdateDeviceOSTargetsRequest();
    $response = null;  // UpdateDeviceOSTargetsResponse

    // Define devices and operating systems to target.

    $targets = array();
    $association = new TargetAssociation();
    $association->DeviceOSTarget = new DeviceOSTarget();
    $association->DeviceOSTarget->DeviceOSList = array();
    $deviceList = new DeviceOS();
    $deviceList->DeviceName = 'Smartphones';
    $deviceList->OSName = 'Windows';
    $association->DeviceOSTarget->DeviceOSList[] = $deviceList;
    $association->Id = $targetId;
    $targets[] = $association;

    // Set the request information.

    $request->TargetAssociations = $targets;

    try
    {
        $response = $proxy->GetService()->UpdateDeviceOSTargets($request);
        printf("Added device OS targets to target %s.\n", $targetId);
    }
    catch (SoapFault $e)
    {
        // Log this fault.

        print "UpdateDeviceOSTargets failed with the following faults:\n";

        if (isset($e->detail->AdApiFaultDetail))
        {
            print "AdApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->AdApiFaultDetail->TrackingId ."\n";

            // Process any system errors.

            $errors = is_array($e->detail->AdApiFaultDetail->Errors->AdApiError)
                    ? $e->detail->AdApiFaultDetail->Errors->AdApiError
                    : array('AdApiError' => $e->detail->AdApiFaultDetail->Errors->AdApiError);

            foreach ($errors as $error)
            {
                if (105 == $error->Code) //  InvalidCredentials
                {
                    print "The specified credentials are not valid or the account is inactive.\n";
                }
                else
                {
                    printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                        $error->ErrorCode, $error->Code, $error->Message, $error->Detail);
                }
            }
        }
        elseif (isset($e->detail->ApiFaultDetail))
        {
            print "ApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->ApiFaultDetail->TrackingId."\n";

            // Process any operation errors.

            if (!empty($e->detail->ApiFaultDetail->OperationErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->OperationErrors->OperationError)
                        ? $e->detail->ApiFaultDetail->OperationErrors->OperationError
                        : array('OperationError' => $e->detail->ApiFaultDetail->OperationErrors->OperationError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        case 106: //  UserIsNotAuthorized
                            print("The user is not authorized to call this operation.\n");
                            break;

                        case 1029: //  CampaignServiceCustomerIdHasToBeSpecified
                            print("The CustomerId header element cannot be null or empty.\n");
                            break;

                        default:
                            printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Message, $error->Details);
                            break;
                    }
                }
            }

            // Process any batch errors.

            if (!empty($e->detail->ApiFaultDetail->BatchErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->BatchErrors->BatchError)
                        ? $e->detail->ApiFaultDetail->BatchErrors->BatchError
                        : array('BatchError' => $e->detail->ApiFaultDetail->BatchErrors->BatchError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        case 2922: //  CampaignServiceInvalidDeviceTarget
                            print("The device name and/or operating system name is not valid. " +
                                "The name cannot be null or empty and must be one of the predefined names. " +
                                "In addition, the combination of device name and operating system must be valid.\n\n");
                            break;

                        case 2923: //  CampaignServiceDuplicateDeviceTarget
                            print("The list of devices cannot contain duplicate device and operating system combinations.\n\n");
                            break;

                        default:
                            printf("Error code: %s (%d)\nIndex: %d\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Index, $error->Message, $error->Details);
                            break;
                    }
                }
            }
        }
        else
        {
            print $e->getCode()." ".$e->getMessage()."\n\n";

            // Output the last request/response.

            print "\nLast SOAP request/response:\n";
            print $proxy->GetWsdl()."\n";
            print $proxy->GetService()->__getLastRequest()."\n";
            print $proxy->GetService()->__getLastResponse()."\n";
        }

        throw new Exception("", 0, $e);
    }
}

// Gets the target associated with the specified campaign and prints the devices
// and operating systems that it targets.

function PrintDeviceTargets($targetId, $proxy)
{
    $deviceTargets = null;

    $deviceTargets = GetDeviceTargets($targetId, $proxy);

    if (null == $deviceTargets->TargetAssociation[0]->DeviceOSTarget)
    {
        print("The campaign targets all devices.\n");
    }
    else
    {
        print("The campaign targets the following devices.\n");

        foreach ($deviceTargets->TargetAssociation as $deviceTarget)
        {
            foreach ($deviceTarget->DeviceOSTarget->DeviceOSList->DeviceOS as $device)
            {
                printf("  %s - %s\n",
                    $device->DeviceName,
                    (null == $device->OSName) ? 'All operating systems' : $device->OSName);
            }
        }
    }
}


// Gets the list of devices and operating systems being targeted.

function GetDeviceTargets($targetId, $proxy)
{
    $request = new GetDeviceOSTargetsByIdsRequest();
    $response = null; // GetDeviceOSTargetsByIdsResponse

    // Set the request information.

    $request->TargetIds = array( $targetId );

    try
    {
        $response = $proxy->GetService()->GetDeviceOSTargetsByIds($request);
    }
    catch (SoapFault $e)
    {
        // Log this fault.

        print "GetDeviceOSTargetsByIds failed with the following faults:\n";

        if (isset($e->detail->AdApiFaultDetail))
        {
            print "AdApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->AdApiFaultDetail->TrackingId ."\n";

            // Process any system errors.

            $errors = is_array($e->detail->AdApiFaultDetail->Errors->AdApiError)
                    ? $e->detail->AdApiFaultDetail->Errors->AdApiError
                    : array('AdApiError' => $e->detail->AdApiFaultDetail->Errors->AdApiError);

            foreach ($errors as $error)
            {
                if (105 == $error->Code) //  InvalidCredentials
                {
                    print "The specified credentials are not valid or the account is inactive.\n";
                }
                else
                {
                    printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                        $error->ErrorCode, $error->Code, $error->Message, $error->Detail);
                }
            }
        }
        elseif (isset($e->detail->ApiFaultDetail))
        {
            print "ApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->ApiFaultDetail->TrackingId."\n";

            // Process any operation errors.

            if (!empty($e->detail->ApiFaultDetail->OperationErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->OperationErrors->OperationError)
                        ? $e->detail->ApiFaultDetail->OperationErrors->OperationError
                        : array('OperationError' => $e->detail->ApiFaultDetail->OperationErrors->OperationError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        case 106: //  UserIsNotAuthorized
                            print("The user is not authorized to call this operation.\n");
                            break;

                        case 206: //  NullArrayArgument
                            print("The list of targets IDs cannot be null or empty.\n");
                            break;

                        case 1029: //  CampaignServiceCustomerIdHasToBeSpecified
                            print("The CustomerId header element cannot be null or empty.\n");
                            break;

                        default:
                            printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Message, $error->Details);
                            break;
                    }
                }
            }

            // Process any batch errors.

            if (!empty($e->detail->ApiFaultDetail->BatchErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->BatchErrors->BatchError)
                        ? $e->detail->ApiFaultDetail->BatchErrors->BatchError
                        : array('BatchError' => $e->detail->ApiFaultDetail->BatchErrors->BatchError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        default:
                            printf("Error code: %s (%d)\nIndex: %d\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Index, $error->Message, $error->Details);
                            break;
                    }
                }
            }
        }
        else
        {
            print $e->getCode()." ".$e->getMessage()."\n\n";

            // Output the last request/response.

            print "\nLast SOAP request/response:\n";
            print $proxy->GetWsdl()."\n";
            print $proxy->GetService()->__getLastRequest()."\n";
            print $proxy->GetService()->__getLastResponse()."\n";
        }

        throw new Exception("", 0, $e);
    }

    return $response->TargetAssociations;
}

// Removes the device targeting from the target object.

function RemoveDeviceTarget($targetId, $proxy)
{
    $request = new UpdateTargetsInLibraryRequest();
    $response = null;  // UpdateTargetsInLibraryResponse

    $targets = GetTarget($targetId, $proxy);

    $targets->Target[0]->IsLibraryTarget = null;  // Must be null
    $targets->Target[0]->Device = null;

    // Set the request information.

    $request->Targets = $targets;

    try
    {
        $response = $proxy->GetService()->UpdateTargetsInLibrary($request);
        printf("Removed device targeting from target %d.\n", $targetId);
    }
    catch (SoapFault $e)
    {
        // Log this fault.

        print "UpdateTargetsInLibrary failed with the following faults:\n";

        if (isset($e->detail->AdApiFaultDetail))
        {
            print "AdApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->AdApiFaultDetail->TrackingId ."\n";

            // Process any system errors.

            $errors = is_array($e->detail->AdApiFaultDetail->Errors->AdApiError)
                    ? $e->detail->AdApiFaultDetail->Errors->AdApiError
                    : array('AdApiError' => $e->detail->AdApiFaultDetail->Errors->AdApiError);

            foreach ($errors as $error)
            {
                if (105 == $error->Code) //  InvalidCredentials
                {
                    print "The specified credentials are not valid or the account is inactive.\n";
                }
                else
                {
                    printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                        $error->ErrorCode, $error->Code, $error->Message, $error->Detail);
                }
            }
        }
        elseif (isset($e->detail->ApiFaultDetail))
        {
            print "ApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->ApiFaultDetail->TrackingId."\n";

            // Process any operation errors.

            if (!empty($e->detail->ApiFaultDetail->OperationErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->OperationErrors->OperationError)
                        ? $e->detail->ApiFaultDetail->OperationErrors->OperationError
                        : array('OperationError' => $e->detail->ApiFaultDetail->OperationErrors->OperationError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        case 106: //  UserIsNotAuthorized
                            print("The user is not authorized to call this operation.\n");
                            break;

                        case 1029: //  CampaignServiceCustomerIdHasToBeSpecified
                            print("The CustomerId header element cannot be null or empty.\n");
                            break;

                        default:
                            printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Message, $error->Details);
                            break;
                    }
                }
            }

            // Process any batch errors.

            if (!empty($e->detail->ApiFaultDetail->BatchErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->BatchErrors->BatchError)
                        ? $e->detail->ApiFaultDetail->BatchErrors->BatchError
                        : array('BatchError' => $e->detail->ApiFaultDetail->BatchErrors->BatchError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        default:
                            printf("Error code: %s (%d)\nIndex: %d\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Index, $error->Message, $error->Details);
                            break;
                    }
                }
            }
        }
        else
        {
            print $e->getCode()." ".$e->getMessage()."\n\n";

            // Output the last request/response.

            print "\nLast SOAP request/response:\n";
            print $proxy->GetWsdl()."\n";
            print $proxy->GetService()->__getLastRequest()."\n";
            print $proxy->GetService()->__getLastResponse()."\n";
        }

        throw new Exception("", 0, $e);
    }
}

// Get the specified target from the library.

function GetTarget($targetId, $proxy)
{
    $request = new GetTargetsByIdsRequest();
    $response = null;  // GetTargetsByIdsResponse

    // Set the request information.

    $request->TargetIds = array( $targetId );
    $request->LocationTargetVersion = 'Latest';

    try
    {
        $response = $proxy->GetService()->GetTargetsByIds($request);
    }
    catch (SoapFault $e)
    {
        // Log this fault.

        print "UpdateTargetsInLibrary failed with the following faults:\n";

        if (isset($e->detail->AdApiFaultDetail))
        {
            print "AdApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->AdApiFaultDetail->TrackingId ."\n";

            // Process any system errors.

            $errors = is_array($e->detail->AdApiFaultDetail->Errors->AdApiError)
                    ? $e->detail->AdApiFaultDetail->Errors->AdApiError
                    : array('AdApiError' => $e->detail->AdApiFaultDetail->Errors->AdApiError);

            foreach ($errors as $error)
            {
                if (105 == $error->Code) //  InvalidCredentials
                {
                    print "The specified credentials are not valid or the account is inactive.\n";
                }
                else
                {
                    printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                        $error->ErrorCode, $error->Code, $error->Message, $error->Detail);
                }
            }
        }
        elseif (isset($e->detail->ApiFaultDetail))
        {
            print "ApiFaultDetail exception encountered\n";
            print "Tracking ID: ".$e->detail->ApiFaultDetail->TrackingId."\n";

            // Process any operation errors.

            if (!empty($e->detail->ApiFaultDetail->OperationErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->OperationErrors->OperationError)
                        ? $e->detail->ApiFaultDetail->OperationErrors->OperationError
                        : array('OperationError' => $e->detail->ApiFaultDetail->OperationErrors->OperationError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        case 106: //  UserIsNotAuthorized
                            print("The user is not authorized to call this operation.\n");
                            break;

                        case 1029: //  CampaignServiceCustomerIdHasToBeSpecified
                            print("The CustomerId header element cannot be null or empty.\n");
                            break;

                        default:
                            printf("Error code: %s (%d)\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Message, $error->Details);
                            break;
                    }
                }
            }

            // Process any batch errors.

            if (!empty($e->detail->ApiFaultDetail->BatchErrors))
            {
                $errors = is_array($e->detail->ApiFaultDetail->BatchErrors->BatchError)
                        ? $e->detail->ApiFaultDetail->BatchErrors->BatchError
                        : array('BatchError' => $e->detail->ApiFaultDetail->BatchErrors->BatchError);

                foreach ($errors as $error)
                {
                    switch ($error->Code)
                    {
                        default:
                            printf("Error code: %s (%d)\nIndex: %d\nMessage: %s\nDetail: %s\n\n",
                                $error->ErrorCode, $error->Code, $error->Index, $error->Message, $error->Details);
                            break;
                    }
                }
            }
        }
        else
        {
            print $e->getCode()." ".$e->getMessage()."\n\n";

            // Output the last request/response.

            print "\nLast SOAP request/response:\n";
            print $proxy->GetWsdl()."\n";
            print $proxy->GetService()->__getLastRequest()."\n";
            print $proxy->GetService()->__getLastResponse()."\n";
        }

        throw new Exception("", 0, $e);
    }

    return $response->Targets;
}



// Callbacks referenced in the SoapClient options.

// Converts long types found in SOAP responses to string types in PHP.

function from_long_xml($xmlFragmentString)
{
    return (string)strip_tags($xmlFragmentString);
}

// Converts PHP string types to long types in SOAP requests.

function to_long_xml($longVal)
{
    return '<long>' . $longVal . '</long>';
}

// Define the proxy class for the Campaign Management service.

Class ClientProxy
{
    private $username;
    private $password;
    private $developerToken;
    private $wsdlUrl;
    private $accountId;
    private $customerId;
    private $service;
    private $namespace;

    public function __construct($username, $password, $token, $accountId, $customerId, $wsdl)
    {
        $this->username = $username;
        $this->password = $password;
        $this->developerToken = $token;
        $this->accountId = $accountId;
        $this->customerId = $customerId;
        $this->wsdlUrl = $wsdl;
        $this->service = $this->GetProxy($wsdl);
    }

    public function GetAccountId() { return $this->accountId; }
    public function GetCustomerId() { return $this->customerId; }
    public function GetService() { return $this->service; }
    public function GetNamespace() { return $this->namespace; }
    public function GetWsdl() { return $this->wsdlUrl; }

    // This function gets the namespace from the WSDL, so you do
    // not have to hardcode it in the client.

    private function GetServiceNamespace($url)
    {
        $doc = new DOMDocument;
        $doc->Load($url);

        $xpath = new DOMXPath($doc);
        $query = "/*/@targetNamespace";

        $attrs = $xpath->query($query);

        // The query will return only one node in the node list.

        foreach($attrs as $attr)
        {
            $namespace = $attr->value;
        }

        return $namespace;
    }

    private function GetProxy($wsdl)
    {
        $this->namespace = $this->GetServiceNamespace($wsdl);

        // Define the SOAP headers. Customer ID is required
        // to get editorial reasons.

        $headers = array();

        $headers[] = new SoapHeader(
            $this->namespace,
            'CustomerAccountId',
            $this->accountId
            );

        $headers[] = new SoapHeader(
            $this->namespace,
            'CustomerId',
            $this->customerId
            );

        $headers[] = new SoapHeader(
            $this->namespace,
            'DeveloperToken',
            $this->developerToken
            );

        $headers[] = new SoapHeader(
            $this->namespace,
            'UserName',
            $this->username
            );

        $headers[] = new SoapHeader(
            $this->namespace,
            'Password',
            $this->password
            );

        // By default, PHP does not return single item arrays as an array type.
        // To force PHP to always return an array for an array type in the
        // response, specify the SOAP_SINGLE_ELEMENT_ARRAYS feature.

        $options = array(
            'trace' => TRUE,
            'exceptions' => TRUE,
            'features' => SOAP_SINGLE_ELEMENT_ARRAYS,

            // Map long type to string type. For details, see
            // from_long_xml and to_long_xml callbacks.

            'typemap' => array(
                array(
                'type_ns' => 'http://www.w3.org/2001/XMLSchema',
                'type_name' => 'long',
                'to_xml' => 'to_long_xml',
                'from_xml' => 'from_long_xml'
                ),
            )
        );

        $proxy = @new SOAPClient($this->wsdlUrl, $options);

        $proxy->__setSoapHeaders($headers);

        return $proxy;
    }
}

// Defines the Campaign Management value sets used in this example.

final class DeviceType
{
    const Smartphones = 'Smartphones';
    const Computers = 'Computers';
}

// Defines the Campaign Management error objects that the operations can return.

final class AdApiError
{
    public $Code;
    public $Detail;
    public $ErrorCode;
    public $Message;
}

final class BatchError
{
    public $Code;
    public $Details;
    public $ErrorCode;
    public $Index;
    public $Message;
}

final class EditorialError
{
    public $Appealable;
    public $Code;
    public $DisapprovedText;
    public $ErrorCode;
    public $Index;
    public $Message;
    public $PublisherCountry;
}

final class OperationError
{
    public $Code;
    public $Details;
    public $ErrorCode;
    public $Message;
}

class ApplicationFault
{
    public $TrackingId;
}

final class ApiFaultDetail extends ApplicationFault
{
    public $BatchErrors;
    public $OperationErrors;
}

final class AdApiFaultDetail extends ApplicationFault
{
    public $Errors;
}

final class EditorialApiFaultDetail extends ApplicationFault
{
    public $BatchErrors;
    public $EditorialErrors;
    public $OperationErrors;
}


// Defines the Campaign Management data objects used in this example.

final class Target
{
    public $Age;
    public $Day;
    public $Device;
    public $Gender;
    public $Hour;
    public $Id;
    public $IsLibraryTarget;
    public $Location;
    public $Name;
}

final class DeviceTarget
{
    public $Devices;
}

final class DeviceOS
{
    public $DeviceName;
    public $OSName;
}

final class DeviceOSTarget
{
    public $DeviceOSList;
}

final class TargetAssociation
{
    public $DeviceOSTarget;
    public $Id;
}


// Defines the request and response messages of the Campaign Management
// operations used in this example.

final class GetDeviceOSTargetsByIdsRequest
{
    public $TargetIds;
}

final class GetDeviceOSTargetsByIdsResponse
{
    public $TargetAssociations;
}

final class GetTargetsByCampaignIdsRequest
{
    public $CampaignIds;
    public $LocationTargetVersion;
}

final class GetTargetsByCampaignIdsResponse
{
    public $Targets;
}

final class GetTargetsByIdsRequest
{
    public $TargetIds;
    public $LocationTargetVersion;
}

final class GetTargetsByIdsResponse
{
    public $Targets;
}

final class UpdateDeviceOSTargetsRequest
{
    public $TargetAssociations;
}

final class UpdateDeviceOSTargetsResponse
{
}

final class UpdateTargetsInLibraryRequest
{
    public $Targets;
}

final class UpdateTargetsInLibraryResponse
{
}

?>

Community Additions

Show: