使用 Python 库在 Google 广告 API v2 Beta 上阻止 IP
Block IPs on Google Ads API v2 Beta using Python Library
我试图通过 Google API v2 阻止 IP 列表,但我收到错误 "Criteria type can not be targeted." on field: operations, on field: create, on field :ip_block。
我的另一个疑问是,我是否需要为列表中的每个 IP 重复创建操作,或者是否有办法将多个 Ip 放在同一个请求中。
client = (google.ads.google_ads.client.GoogleAdsClient.load_from_storage(path="./google-ads.yaml"))
campaign_criterion_operation = client.get_type('CampaignCriterionOperation', version='v2')
campaign_criterion = campaign_criterion_operation.create
campaign_criterion.campaign.value = campaign_service.campaign_path(customer, campaign)
campaign_criterion.ip_block.ip_address.value = "xxx.xxx.xxx.xxx"
campaign_criterion_response = campaign_criterion_service.mutate_campaign_criteria(customer, [campaign_criterion_operation])
for reponse in campaign_criterion_response.results:
print('Added campaign criterion "%s".' % reponse.resource_name)
我认为您收到错误是因为您没有将标准设置为否定。我没有使用 python 库,但我正在使用 PHP 库。
这是我的样子;
$campaign_criterion = new CampaignCriterion([
'ip_block' => new IpBlockInfo([
'ip_address' => 'IP_ADDRESS_HERE'
]),
'negative' => true, // setting it to negative
'campaign' => ResourceNames::forCampaign('XXXXXXXXXX', 'XXXXXXXXXXXX')
]);
是的,您必须为要阻止的每个 IP 地址创建一个活动标准。
我试图通过 Google API v2 阻止 IP 列表,但我收到错误 "Criteria type can not be targeted." on field: operations, on field: create, on field :ip_block。 我的另一个疑问是,我是否需要为列表中的每个 IP 重复创建操作,或者是否有办法将多个 Ip 放在同一个请求中。
client = (google.ads.google_ads.client.GoogleAdsClient.load_from_storage(path="./google-ads.yaml"))
campaign_criterion_operation = client.get_type('CampaignCriterionOperation', version='v2')
campaign_criterion = campaign_criterion_operation.create
campaign_criterion.campaign.value = campaign_service.campaign_path(customer, campaign)
campaign_criterion.ip_block.ip_address.value = "xxx.xxx.xxx.xxx"
campaign_criterion_response = campaign_criterion_service.mutate_campaign_criteria(customer, [campaign_criterion_operation])
for reponse in campaign_criterion_response.results:
print('Added campaign criterion "%s".' % reponse.resource_name)
我认为您收到错误是因为您没有将标准设置为否定。我没有使用 python 库,但我正在使用 PHP 库。
这是我的样子;
$campaign_criterion = new CampaignCriterion([
'ip_block' => new IpBlockInfo([
'ip_address' => 'IP_ADDRESS_HERE'
]),
'negative' => true, // setting it to negative
'campaign' => ResourceNames::forCampaign('XXXXXXXXXX', 'XXXXXXXXXXXX')
]);
是的,您必须为要阻止的每个 IP 地址创建一个活动标准。