我想使用Google Adwords API(v201509)获取目标网址。 用PHP编写。
在下面的代码中,我试图通过使用AdGroupAdService的'get'方法获取网址。 因此,我可以正确地获得ad-> displayUrl但无法获得ad-> url和ad-> finalUrls(null给定)。
我做错了什么?
adwords.php,代码如下 -
$adGroupAdService = $user->GetService('AdGroupAdService', ADWORDS_VERSION);
// Create selector.
$selector = new Selector();
$selector->fields = array('Headline', 'Id');
$selector->ordering[] = new OrderBy('Headline', 'ASCENDING');
// Create paging controls.
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
do {
// Make the get request.
$page = $adGroupAdService->get($selector);
// Display results.
if (isset($page->entries)) {
foreach ($page->entries as $adGroupAd) {
array_push($googleAccountStructure, $adGroupAd);
//var_dump($adGroupAd);
}
}
// Advance the paging index.
$selector->paging->startIndex += AdWordsConstants::RECOMMENDED_PAGE_SIZE;
} while ($page->totalNumEntries > $selector->paging->startIndex);
答案 0 :(得分:3)
请使用此
更新您的选择器字段$selector->fields = array('Headline', 'Id', 'CreativeFinalUrls', 'Url');
根据adwords api doc,如果您使用升级版网址,则需要在选择器字段中传递最终网址
https://developers.google.com/adwords/api/docs/reference/v201509/AdGroupAdService.Ad#finalUrls