AdWordsUser::GetService PHP Method

GetService() public method

Gets the service by its service name and group.
public GetService ( string $serviceName, string | null $version = null, string | null $server = null, SoapClientFactory $serviceFactory = null, boolean | null $validateOnly = null, boolean | null $partialFailure = null ) : SoapClient
$serviceName string the service name
$version string | null the version of the service to get. If null, then the default version will be used
$server string | null 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
$validateOnly boolean | null if the service should be created in validateOnly mode
$partialFailure boolean | null if the service should be created in partialFailure mode
return SoapClient the instantiated service
    public function GetService($serviceName, $version = null, $server = null, SoapClientFactory $serviceFactory = null, $validateOnly = null, $partialFailure = null)
    {
        $this->ValidateUser();
        if ($serviceFactory === null) {
            if ($version === null) {
                $version = $this->GetDefaultVersion();
            }
            if ($server === null) {
                $server = $this->GetDefaultServer();
            }
            $serviceFactory = new AdWordsSoapClientFactory($this, $version, $server, $validateOnly, $partialFailure);
        }
        return parent::GetServiceSoapClient($serviceName, $serviceFactory);
    }

Usage Example

Example #1
1
function AddTextAdsExample(AdWordsUser $user, $adGroupId)
{
    // Get the service, which loads the required classes.
    $adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
    $numAds = 5;
    $operations = array();
    for ($i = 0; $i < $numAds; $i++) {
        // Create text ad.
        $textAd = new TextAd();
        $textAd->headline = 'Cruise #' . uniqid();
        $textAd->description1 = 'Visit the Red Planet in style.';
        $textAd->description2 = 'Low-gravity fun for everyone!';
        $textAd->displayUrl = 'www.example.com';
        $textAd->finalUrls = array('http://www.example.com');
        // Create ad group ad.
        $adGroupAd = new AdGroupAd();
        $adGroupAd->adGroupId = $adGroupId;
        $adGroupAd->ad = $textAd;
        // Set additional settings (optional).
        $adGroupAd->status = 'PAUSED';
        // Create operation.
        $operation = new AdGroupAdOperation();
        $operation->operand = $adGroupAd;
        $operation->operator = 'ADD';
        $operations[] = $operation;
    }
    // Make the mutate request.
    $result = $adGroupAdService->mutate($operations);
    // Display results.
    foreach ($result->value as $adGroupAd) {
        printf("Text ad with headline '%s' and ID '%s' was added.\n", $adGroupAd->ad->headline, $adGroupAd->ad->id);
    }
}
All Usage Examples Of AdWordsUser::GetService