0

在过去的几年里,我使用 Google AdWords API 来管理一些 google AdWords 操作,但是在迁移到新版本之后,我让它重现了我在旧版本中所做的所有事情,除了一件事:删除特定标签一个特定的广告组,这是旧版本的样子:

from googleads import adwords
def remove_label_adgroups(ad_group_id):
  # Initialize appropriate service.
  client = adwords.AdWordsClient.LoadFromStorage("googleads.yaml")
  campaign_service = client.GetService('AdGroupService', version='v201809')

  operations = [
      {  'operator': 'REMOVE',
          'operand': {
              'adGroupId': ad_group_id,
              'labelId': 'xxxx',
                        }  } ]
  campaign_service.mutateLabel(operations)
remove_label_adgroups(ad_group_id)

这是不起作用的新版本:

from google.ads.googleads.client import GoogleAdsClient
from google.ads.googleads.errors import GoogleAdsException
def rmove(ad_group_id):
    client=GoogleAdsClient.load_from_storage("./google-ads.yaml",version="v8")
    # Get an instance of CampaignLabelService client.


    customer_id="xxx"
    label_id="xxx"
    ad_group_ad_service = client.get_service("AdGroupLabelOperation")
    ad_group_ad_operation = client.get_type("AdGroupAdOperation")

    resource_name = ad_group_ad_service.ad_group_ad_path(customer_id, ad_group_id,label_id)
    ad_group_ad_operation.remove = resource_name

    ad_group_ad_service.mutate_ad_group_ads(customer_id=customer_id, operations=[ad_group_ad_operation])


rmove("xxxx")

我将不胜感激

4

0 回答 0