AdWordsUser::LoadService PHP Method

LoadService() public method

Loads the classes within a service, so they can be used before the service is constructed.
public LoadService ( string $serviceName, string | null $version = null )
$serviceName string the service name
$version string | null the version of the service to get. If null, then the default version will be used
    public function LoadService($serviceName, $version = null)
    {
        if ($version === null) {
            $version = $this->GetDefaultVersion();
        }
        $serviceFactory = new AdWordsSoapClientFactory($this, $version, null, null, null);
        $serviceFactory->DoRequireOnce($serviceName);
    }

Usage Example

/**
 * Runs the example.
 * @param AdWordsUser $user the user to run the example with
 * @param string $filePath the path of the file to download the report to
 */
function DownloadCriteriaReportExample(AdWordsUser $user, $filePath)
{
    // Load the service, so that the required classes are available.
    $user->LoadService('ReportDefinitionService', ADWORDS_VERSION);
    // Create selector.
    $selector = new Selector();
    $selector->fields = array('CampaignId', 'AdGroupId', 'Id', 'Criteria', 'CriteriaType', 'Impressions', 'Clicks', 'Cost');
    // Optional: use predicate to filter out paused criteria.
    $selector->predicates[] = new Predicate('Status', 'NOT_IN', array('PAUSED'));
    // Create report definition.
    $reportDefinition = new ReportDefinition();
    $reportDefinition->selector = $selector;
    $reportDefinition->reportName = 'Criteria performance report #' . uniqid();
    $reportDefinition->dateRangeType = 'LAST_7_DAYS';
    $reportDefinition->reportType = 'CRITERIA_PERFORMANCE_REPORT';
    $reportDefinition->downloadFormat = 'CSV';
    // Exclude criteria that haven't recieved any impressions over the date range.
    $reportDefinition->includeZeroImpressions = false;
    // Set additional options.
    $options = array('version' => ADWORDS_VERSION);
    // Optional: Set skipReportHeader, skipColumnHeader, skipReportSummary to
    //     suppress headers or summary rows.
    // $options['skipReportHeader'] = true;
    // $options['skipColumnHeader'] = true;
    // $options['skipReportSummary'] = true;
    // Optional: Set includeZeroImpressions to include zero impression rows in
    //     the report output.
    // $options['includeZeroImpressions'] = true;
    // Download report.
    ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
    printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}
All Usage Examples Of AdWordsUser::LoadService