本文整理汇总了PHP中AdWordsUser::LoadService方法的典型用法代码示例。如果您正苦于以下问题:PHP AdWordsUser::LoadService方法的具体用法?PHP AdWordsUser::LoadService怎么用?PHP AdWordsUser::LoadService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AdWordsUser
的用法示例。
在下文中一共展示了AdWordsUser::LoadService方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: DownloadCriteriaReportExample
/**
* 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);
}
示例2: DownloadCriteriaReportWithAwqlExample
/**
* 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 DownloadCriteriaReportWithAwqlExample(AdWordsUser $user, $filePath, $reportFormat)
{
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', 'v201206');
// Prepare a date range for the last week. Instead you can use 'LAST_7_DAYS'.
$dateRange = sprintf('%d,%d', date('Ymd', strtotime('-7 day')), date('Ymd', strtotime('-1 day')));
// Create report query.
$reportQuery = 'SELECT CampaignId, AdGroupId, Id, Criteria, CriteriaType, ' . 'Impressions, Clicks, Cost FROM CRITERIA_PERFORMANCE_REPORT ' . 'WHERE Status IN [ACTIVE, PAUSED] DURING ' . $dateRange;
// Set additional options.
$options = array('version' => 'v201206');
// Download report.
ReportUtils::DownloadReportWithAwql($reportQuery, $filePath, $user, $reportFormat, $options);
printf("Report was downloaded to '%s'.\n", $filePath);
}
示例3: DownloadCriteriaReportExample
/**
* 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);
// Optional: Set clientCustomerId to get reports of your child accounts
// $user->SetClientCustomerId('INSERT_CLIENT_CUSTOMER_ID_HERE');
// 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';
// 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 useRawEnumValues to return enum values instead of enum
// display values.
// $options['useRawEnumValues'] = true;
//
// Optional: Set includeZeroImpressions to include zero impression rows in
// the report output.
// $options['includeZeroImpressions'] = true;
// Download report.
$reportUtils = new ReportUtils();
$reportUtils->DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}
示例4: DownloadCriteriaReportExample
/**
* 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');
// Filter out deleted criteria.
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DELETED'));
// 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, 'returnMoneyInMicros' => TRUE);
// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report with name '%s' was downloaded to '%s'.\n", $reportDefinition->reportName, $filePath);
}
示例5: ParallelReportDownloadExample
/**
* Runs the example.
* @param AdWordsUser $user the user to run the example with
*/
function ParallelReportDownloadExample(AdWordsUser $user)
{
// 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', 'Impressions', 'Clicks', 'Cost');
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Custom ADGROUP_PERFORMANCE_REPORT';
$reportDefinition->dateRangeType = 'LAST_7_DAYS';
$reportDefinition->reportType = 'ADGROUP_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
// 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 useRawEnumValues to return enum values instead of enum
// display values.
// $options['useRawEnumValues'] = true;
//
// Optional: Set includeZeroImpressions to include zero impression rows in
// the report output.
// $options['includeZeroImpressions'] = true;
$customerIds = getAllManagedCustomerIds($user);
printf("Downloading reports for %d managed customers.\n", count($customerIds));
$successfulReports = array();
$failedReports = array();
$reportDir = sys_get_temp_dir();
$reportUtils = new ReportUtils();
foreach ($customerIds as $customerId) {
$filePath = sprintf('%s.csv', tempnam($reportDir, 'adgroup_'));
$user->SetClientCustomerId($customerId);
$retryCount = 0;
$doContinue = true;
do {
$retryCount++;
try {
$reportUtils->DownloadReport($reportDefinition, $filePath, $user, $options);
printf("Report for client customer ID %d successfully downloaded to: %s\n", $customerId, $filePath);
$successfulReports[$customerId] = $filePath;
$doContinue = false;
} catch (ReportDownloadException $e) {
printf("Report attempt #%d for client customer ID %d was not downloaded" . " due to: %s\n", $retryCount, $customerId, $e->getMessage());
if ($e->GetHttpCode() >= 500 && $retryCount < MAX_RETRIES) {
$sleepTime = $retryCount * BACKOFF_FACTOR;
printf("Sleeping %d seconds before retrying report for client customer " . "ID %d.\n", $sleepTime, $customerId);
sleep($sleepTime);
} else {
printf("Report request failed for client customer ID %d.\n", $customerId);
$failedReports[$customerId] = $filePath;
$doContinue = false;
}
}
} while ($doContinue === true);
}
print "All downloads completed. Results:\n";
print "Successful reports:\n";
foreach ($successfulReports as $customerId => $filePath) {
printf("\tClient ID %d => '%s'\n", $customerId, $filePath);
}
print "Failed reports:\n";
foreach ($failedReports as $customerId => $filePath) {
printf("\tClient ID %d => '%s'\n", $customerId, $filePath);
}
print "End of results.\n";
}