2015-05-18 34 views
1

我試圖通過Adwords API檢索升級版網址,但是我得到的所有內容都是NULL。我使用的是最新版本的客戶端庫(v201502)的 下面是我使用PHP Adwords API獲得升級網址

$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

可能是一個愚蠢的問題,而是你是拉低使用升級後的網址或者是使用包含目標仍然是廣告嗎? –

+0

它使用最終的網址,但它在使用最終網址的所有廣告上返回null。使用目標網址的廣告工作正常。 客戶端庫中有一個關於如何添加最終網址的示例,但我無法找到任何有關如何將其拉回的方法。 –

+0

要檢查的另一件事是,最終的url將作爲一個字符串數組而不是一個字符串返回。你的代碼設置是否可以處理這個問題https://developers.google.com/adwords/api/docs/reference/v201502/AdGroupAdService.TextAd –

回答

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);