2

以下は、Python API を使用して、Adwords からすべてのキャンペーンとキャンペーンの詳細を取得しようとする私の基本コードです。MCCを使用しています。では、顧客 ID が与えられた場合、アカウント内のすべてのキャンペーンをループして、すべてのキャンペーン設定を取得するにはどうすればよいでしょうか?

import os
import datetime
from adspygoogle.adwords.AdWordsClient import AdWordsClient
from adspygoogle.common import Utils
from pprint import pprint

google_service = 'https://adwords.google.com'
headers = {
      'email': 'test@gmail.com',
      'password': 'test',
      'userAgent': 'Test',
      'developerToken': 'xxxxxxxxxxx',
    }


google_service = 'https://adwords.google.com'
api_version = 'v201109'

client = AdWordsClient(headers=headers)
client.use_mcc = True
client.SetDebug=True
client.SetClientCustomerId='11111111111'
campaign_service = client.GetCampaignService(google_service, api_version)
4

2 に答える 2

0

私はPythonライブラリにあまり詳しくありませんが、例をざっと見てみると、奇妙なことに、最初に作成する必要のあるサンプルコードがレポートフォルダーに配置されていることがわかりました。キャンペーン統計をダウンロードするための例をチェックすると、必要なものを抽出する方法を理解できるはずです。

必要なフィールドを見つけるには、 CampaignServiceのドキュメントを参照する必要があります。また、キャンペーン設定の多くは、他のサービス( CampaignCriterionSerivceCampaignTargetService、およびCampaignAdExtensionService )を介して取得する必要があることを忘れないでください。

さらにサポートが必要な場合は、公式のAdWordsAPIフォーラムが最適です。営業時間中は、通常、GoogleAdWordsAPIエンジニアから回答があります。

于 2012-04-14T09:23:55.963 に答える
0

以下は機能し、Adwords Github repoからの例として提供されています。これにより、MCC アカウントのすべてのクライアント ID のリストが返されます。そこから、ループを記述して、各クライアント ID に対して特定の機能を実行できます。

from googleads import adwords

def DisplayAccountTree(account, accounts, links, depth=0):
  prefix = '-' * depth * 2
  print '%s%s, %s' % (prefix, account['customerId'], account['name'])
  if account['customerId'] in links:
    for child_link in links[account['customerId']]:
      child_account = accounts[child_link['clientCustomerId']]
      DisplayAccountTree(child_account, accounts, links, depth + 1)

def main(client):
  # Initialize appropriate service.
  managed_customer_service = client.GetService(
      'ManagedCustomerService', version='v201506')

  # Construct selector to get all accounts.
  selector = {
      'fields': ['CustomerId', 'Name']
  }
  # Get serviced account graph.
  graph = managed_customer_service.get(selector)
  if 'entries' in graph and graph['entries']:
    # Create map from customerId to parent and child links.
    child_links = {}
    parent_links = {}
    if 'links' in graph:
      for link in graph['links']:
        if link['managerCustomerId'] not in child_links:
          child_links[link['managerCustomerId']] = []
        child_links[link['managerCustomerId']].append(link)
        if link['clientCustomerId'] not in parent_links:
          parent_links[link['clientCustomerId']] = []
        parent_links[link['clientCustomerId']].append(link)
    # Create map from customerID to account and find root account.
    accounts = {}
    root_account = None
    for account in graph['entries']:
      accounts[account['customerId']] = account
      if account['customerId'] not in parent_links:
        root_account = account
    # Display account tree.
    if root_account:
      print 'CustomerId, Name'
      DisplayAccountTree(root_account, accounts, child_links, 0)
    else:
      print 'Unable to determine a root account'
  else:
    print 'No serviced accounts were found'

if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()
  main(adwords_client)
于 2015-09-24T16:00:12.470 に答える