编辑错误main()获得了2个位置参数,但给出了3个



我正在测试Google AdWords API功能(注意:此问题不是直接针对Google Ad Words API)。

我面临的错误说:main()进行了2个位置论点,但有3个被给予的

我做了什么:

1)创建了一个具有关键字charfield

的关键字模型

2)创建了一个具有类型charfield

的形式元素的关键字范围

3)使用HTML页面中的表单通过POST方法获取关键字

4)帖子后,将URL路由到视图keyword_add,该关键字_ADD设置了两个值,即

adwords_client = adwords.AdWordsClient.LoadFromStorage()
ad_group_id = 'XXXXXXXXX` 

另外,它使用

获得关键字模型的值
new_keyword = Keyword.objects.all()

然后使用函数调用

调用位于python脚本中的函数
    ad_group_update.main(adwords_client, ad_group_id, new_keyword)

5)使用三个参数adwords_client,ad_group_id& amp;new_keyword

我这样做时会出现以下错误:

1)执行main()

时错误

除此错误外,我在代码中还有另一个问题:

from googleads import adwords

AD_GROUP_ID = 'INSERT_AD_GROUP_ID_HERE'

def main(client, ad_group_id, keyword):
  # Initialize appropriate service.
  ad_group_criterion_service = client.GetService(
      'AdGroupCriterionService', version='v201710')
  # Construct keyword ad group criterion object.
  keyword1 = {
      'xsi_type': 'BiddableAdGroupCriterion',
      'adGroupId': ad_group_id,
      'criterion': {
          'xsi_type': 'Keyword',
          'matchType': 'BROAD',
          'text': 'MARS'
      },
      # These fields are optional.
      'userStatus': 'PAUSED',
      'finalUrls': {
          'urls': ['http://example.com/keyword']
      }
  }
  keyword2 = {
      'xsi_type': 'NegativeAdGroupCriterion',
      'adGroupId': ad_group_id,
      'criterion': {
          'xsi_type': 'Keyword',
          'matchType': 'EXACT',
          'text': 'pluto'
      }
  }
  # Construct operations and add ad group criteria.
  operations = [
      {
          'operator': 'ADD',
          'operand': keyword1
      },
      {
          'operator': 'ADD',
          'operand': keyword2
      }
  ]
  ad_group_criteria = ad_group_criterion_service.mutate(
      operations)['value']
  # Display results.
  for criterion in ad_group_criteria:
    print(('Keyword ad group criterion with ad group id "%s", criterion id '
           '"%s", text "%s", and match type "%s" was added.'
           % (criterion['adGroupId'], criterion['criterion']['id'],
              criterion['criterion']['text'],
              criterion['criterion']['matchType'])))

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

如何使用参数new_keyword更新关键字的文本元素?

在您的代码

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

您正在通过2个参数,但def main(__, __, __)进行了3个参数。

main(adwords_client, AD_GROUP_ID, )

这就是为什么您会遇到错误。

最新更新