DfpUser::GetService PHP Method

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
    public function GetService($serviceName, $version = null, $server = null, SoapClientFactory $serviceFactory = null)
    {
        $this->ValidateUser();
        if ($serviceFactory === null) {
            if ($version === null) {
                $version = $this->GetDefaultVersion();
            }
            if ($server === null) {
                $server = $this->GetDefaultServer();
            }
            $serviceFactory = new DfpSoapClientFactory($this, $version, $server);
        }
        return parent::GetServiceSoapClient($serviceName, $serviceFactory);
    }

Usage Example

/**
 * 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);
}
All Usage Examples Of DfpUser::GetService