Adwords API CampaignCriterionService IpBlock空IpAddress问题

时间:2015-03-25 10:32:44

标签: google-adwords

我们在获取IpBlock标准的IpAddress值时遇到了CampaignCriterionService的问题。

https://developers.google.com/adwords/api/docs/reference/v201502/CampaignCriterionService.IpBlock

无法获取IpAddress值。如果你在选择器中使用它 - 你会收到错误[SelectorError.INVALID_FIELD_NAME @ serviceSelector;触发: 'Ip地址']。

$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'IpAddress');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);

经过数小时的努力,我们发现你应该使用“KeywordText”代替“IpAddress”来获得正确的价值。这根本不明显。希望这个提示能节省一些时间和精力。这些事情应该在文档中。因此,工作代码如下所示:

$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'KeywordText');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);

1 个答案:

答案 0 :(得分:0)

如果你想使用IpAddress作为谓词进行搜索,你应该使用相同的" KeywordText",有一个例子:

$selector = new Selector();
$selector->fields = array('Id', 'CriteriaType', 'KeywordText');
$selector->predicates[] = new Predicate('CampaignId', 'EQUALS', $campaign->google_id);
$selector->predicates[] = new Predicate('CriteriaType', 'EQUALS', 'IP_BLOCK');
$selector->predicates[] = new Predicate('KeywordText', 'EQUALS', '192.168.0.1/32');
$selector->paging = new Paging(0, AdWordsConstants::RECOMMENDED_PAGE_SIZE);
$page = $campaignCriterionService->get($selector);
print_r($page);

产生输出:

CampaignCriterionPage Object
(
    [entries] => Array
        (
            [0] => NegativeCampaignCriterion Object
                (
                    [campaignId] => 167195728
                    [isNegative] => 1
                    [criterion] => IpBlock Object
                        (
                            [ipAddress] => 192.168.0.1/32
                            [id] => 23078300211
                            [type] => IP_BLOCK
                            [CriterionType] => IpBlock
                            [_parameterMap:Criterion:private] => Array
                                (
                                    [Criterion.Type] => CriterionType
                                )

                        )

                    [bidModifier] => 
                    [forwardCompatibilityMap] => 
                    [CampaignCriterionType] => NegativeCampaignCriterion
                    [_parameterMap:CampaignCriterion:private] => Array
                        (
                            [CampaignCriterion.Type] => CampaignCriterionType
                        )

                )

        )

    [totalNumEntries] => 1
    [PageType] => CampaignCriterionPage
    [_parameterMap:Page:private] => Array
        (
            [Page.Type] => PageType
        )

)