如何使用 Google 广告 API 和 Python 更改关键字状态

How to change keyword status with Google Ads API and Python

我试图通过 Google 广告更改关键字状态 API 以下代码显示了如何更新关键字出价...但是,我正在寻找一种设置关键字的方法状态为暂停,我无法在文档中找到任何信息来暂停关键字

from googleads import adwords


AD_GROUP_ID = 'INSERT_AD_GROUP_ID_HERE'
CRITERION_ID = 'INSERT_KEYWORD_CRITERION_ID_HERE'


def main(client, ad_group_id, criterion_id):
           # Initialize appropriate service.
           ad_group_criterion_service = client.GetService(
                                       'AdGroupCriterionService', version='v201809')

           # Construct operations and update bids.

           operations = [{
                 'operator': 'SET',
                 'operand': {
                 'xsi_type': 'BiddableAdGroupCriterion',
                 'adGroupId': ad_group_id,
                 'criterion': {
                 'id': criterion_id,
                  },
                'biddingStrategyConfiguration': {
                'bids': [
                     {
                    'xsi_type': 'CpcBid',
                    'bid': {
                      'microAmount': '1000000'
                      }
                    }
                  ]
                }
              }
            }]
        ad_group_criteria = ad_group_criterion_service.mutate(operations)

 # Display results.
 if 'value' in ad_group_criteria:
    for criterion in ad_group_criteria['value']:
      if criterion['criterion']['Criterion.Type'] == 'Keyword':
          print('Ad group criterion with ad group id "%s" and criterion id '
                '"%s" currently has bids:'
                % (criterion['adGroupId'], criterion['criterion']['id']))
      for bid in criterion['biddingStrategyConfiguration']['bids']:
         print('\tType: "%s", value: %s' % (bid['Bids.Type'],)
              bid['bid']['microAmount'])
else:
    print('No ad group criteria were updated.')


if __name__ == '__main__':
     # Initialize client object.
     adwords_client = adwords.AdWordsClient.LoadFromStorage()

     main(adwords_client, AD_GROUP_ID, CRITERION_ID)

在此先感谢您的帮助...

经过更多研究,我找到了以下指南。

https://developers.google.com/adwords/api/docs/reference/v201809/AdGroupCriterionService.BiddableAdGroupCriterion#userstatus

为了修改关键字状态,构造操作需要像这样。

 operations = [{
      'operator': 'SET',
      'operand': {
            'xsi_type': 'BiddableAdGroupCriterion',
            'adGroupId': ad_group_id,
            'criterion': {
                   'id': criterion_id,
                 },
                   'userStatus': 'ENABLED'
              }
           }]