为 Google Adwords API 设置客户 ID

Posted

技术标签:

【中文标题】为 Google Adwords API 设置客户 ID【英文标题】:Set customer ID for Google Adwords API 【发布时间】:2019-02-03 21:03:51 【问题描述】:

我尝试使用 Google Adwords API,这里有官方库:https://github.com/googleads/googleads-python-lib

我在 Google Adwords 上使用经理帐户并希望使用我客户的帐户。

我可以获得所有 Adwords 帐户 ID(如 123-456-7891),但我不知道如何将帐户 ID 作为参数传递给我的 Google Adwords 函数。

这是我的主要功能:

def main(argv):
    adwords_client = adwords.AdWordsClient.LoadFromStorage(path="googleads.yaml")
    add_campaign(adwords_client)

我在官方示例中看到了任何 Account ID 参数,如:

import datetime
import uuid
from googleads import adwords

def add_campaign(client):
  # Initialize appropriate services.
  campaign_service = client.GetService('CampaignService', version='v201809')
  budget_service = client.GetService('BudgetService', version='v201809')

  # Create a budget, which can be shared by multiple campaigns.
  budget = 
      'name': 'Interplanetary budget #%s' % uuid.uuid4(),
      'amount': 
          'microAmount': '50000000'
      ,
      'deliveryMethod': 'STANDARD'
  

  budget_operations = [
      'operator': 'ADD',
      'operand': budget
  ]

  # Add the budget.
  budget_id = budget_service.mutate(budget_operations)['value'][0][
      'budgetId']

  # Construct operations and add campaigns.
  operations = [
      'operator': 'ADD',
      'operand': 
          'name': 'Interplanetary Cruise #%s' % uuid.uuid4(),
          # Recommendation: Set the campaign to PAUSED when creating it to
          # stop the ads from immediately serving. Set to ENABLED once you've
          # added targeting and the ads are ready to serve.
          'status': 'PAUSED',
          'advertisingChannelType': 'SEARCH',
          'biddingStrategyConfiguration': 
              'biddingStrategyType': 'MANUAL_CPC',
          ,
          'endDate': (datetime.datetime.now() +
                      datetime.timedelta(365)).strftime('%Y%m%d'),
          # Note that only the budgetId is required
          'budget': 
              'budgetId': budget_id
          ,
          'networkSetting': 
              'targetGoogleSearch': 'true',
              'targetSearchNetwork': 'true',
              'targetContentNetwork': 'false',
              'targetPartnerSearchNetwork': 'false'
          ,
          # Optional fields
          'startDate': (datetime.datetime.now() +
                        datetime.timedelta(1)).strftime('%Y%m%d'),
          'frequencyCap': 
              'impressions': '5',
              'timeUnit': 'DAY',
              'level': 'ADGROUP'
          ,
          'settings': [
              
                  'xsi_type': 'GeoTargetTypeSetting',
                  'positiveGeoTargetType': 'DONT_CARE',
                  'negativeGeoTargetType': 'DONT_CARE'
              
          ]
      
  , 
      'operator': 'ADD',
      'operand': 
          'name': 'Interplanetary Cruise banner #%s' % uuid.uuid4(),
          'status': 'PAUSED',
          'biddingStrategyConfiguration': 
              'biddingStrategyType': 'MANUAL_CPC'
          ,
          'endDate': (datetime.datetime.now() +
                      datetime.timedelta(365)).strftime('%Y%m%d'),
          # Note that only the budgetId is required
          'budget': 
              'budgetId': budget_id
          ,
          'advertisingChannelType': 'DISPLAY'
      
  ]
  campaigns = campaign_service.mutate(operations)

如何告诉 Adwords API 我要在哪个帐户中添加此广告系列?

感谢您的帮助!

【问题讨论】:

【参考方案1】:

好吧,我错了,我错过了文档方法 (http://googleads.github.io/googleads-python-lib/googleads.adwords.AdWordsClient-class.html#SetClientCustomerId)。

    # ID of your customer here
    CUSTOMER_SERVICE_ID = '4852XXXXX'

    # Load customer account access
    client = adwords.AdWordsClient.LoadFromStorage(path="googleads.yaml")
    client.SetClientCustomerId(CUSTOMER_SERVICE_ID)

现在客户 ID 与 AdwordsClient 变量关联为“客户”设置为其他功能的参数。

【讨论】:

以上是关于为 Google Adwords API 设置客户 ID的主要内容,如果未能解决你的问题,请参考以下文章

Google AdWords API Python 客户端仅返回 RefreshError: invalid_grant: Bad Request

Google Adwords API 错误 - OAuth 客户端已删除

如何开始使用 Google AdWords API?

如何仅使用客户 ID 在 Google Adwords API 中关联帐户?

使用 google adwords api

google adwords api 与 google-adwords-api gem