我正在尝试通过Adwords API检索升级后的网址,但我得到的只是NULL。我正在使用最新版本的客户端库(v201502) 这是我正在使用的代码
$adGroupAdService = $this->oGAW->GetService('AdGroupAdService', ADWORDS_VERSION);
$selector = new Selector();
$selector->fields = array('AdGroupId');
// Create predicates.
$selector->predicates[] =
new Predicate('AdGroupId', 'IN', array($adGroupId));
$selector->predicates[] =
new Predicate('AdType', 'IN', array('TEXT_AD', 'DYNAMIC_SEARCH_AD'));
// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $adGroupAdService->get($selector);
然后它返回
object(TextAd)[107]
public 'headline' => string 'headline'
public 'description1' => string 'description1'
public 'description2' => string 'description2'
public 'id' => string '76813511440' (length=11)
public 'url' => null
public 'displayUrl' => string 'test.nl/test'
public 'finalUrls' => null
public 'finalMobileUrls' => null
public 'finalAppUrls' => null
public 'trackingUrlTemplate' => null
public 'urlCustomParameters' => null
public 'devicePreference' => null
public 'AdType' => string 'TextAd' (length=6)
private '_parameterMap' (Ad) =>
array (size=1)
'Ad.Type' => string 'AdType' (length=6)
我做错了什么?
谢谢!
答案 0 :(得分:2)
您正在寻找的字段是'CreativeFinalUrls',只需将其添加到您的选择器字段中,它将返回textAd.finalUrls中的最终网址数组。
$selector->fields = array('AdGroupId', 'CreativeFinalUrls');
请参阅https://developers.google.com/adwords/api/docs/appendix/selectorfields?hl=en#v201506
答案 1 :(得分:1)
我找到了解决方法,我现在正在使用ReportDefinitionService来获取今天的AD_PERFORMANCE_REPORT。
最终网址显示在它返回的csv中。
$oAdwords = Utility_Adwords::getInstance($iCredentials);
$user = $oAdwords->getAdwordsUser($iCredentials, $iCustomerId);
// Load the service, so that the required classes are available.
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION_SPEND);
// Create selector.
$selector = new Selector();
$selector->fields = array('CampaignId', 'CampaignName','CampaignStatus', 'AdGroupId', 'Id', 'AdGroupName', 'AdGroupStatus', 'Status', 'AdType', 'DisplayUrl', 'CreativeDestinationUrl', 'CreativeFinalUrls', 'CreativeTrackingUrlTemplate', 'CreativeUrlCustomParameters');
// Filter out removed criteria.
$selector->predicates[] = new Predicate('CampaignId', 'IN', $aCampaigns);
$selector->predicates[] = new Predicate('AdGroupStatus', 'NOT_IN', array('REMOVED'));
$selector->predicates[] = new Predicate('Status', 'NOT_IN', array('DISABLED'));
// Create report definition.
$reportDefinition = new ReportDefinition();
$reportDefinition->selector = $selector;
$reportDefinition->reportName = 'Ad Performance Report #' . uniqid();
$reportDefinition->dateRangeType = 'TODAY';
$reportDefinition->reportType = 'AD_PERFORMANCE_REPORT';
$reportDefinition->downloadFormat = 'CSV';
// Set additional options.
$options = array('version' => ADWORDS_VERSION_SPEND);
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);