【问题标题】:Get all clientID from MCC adwords account by adwordsAPI通过 adwords API 从 MCC adwords 帐户获取所有客户 ID
【发布时间】:2012-06-20 17:12:20
【问题描述】:

我想从我的 MCC 帐户中检索所有 clientID。我正在使用此代码

              AdWordsUser user = new AdWordsUser(adwordsPropertyService.getEmail(), adwordsPropertyService.getPassword(),
                      null, adwordsPropertyService.getUseragent(), adwordsPropertyService.getDeveloperToken(),
                      adwordsPropertyService.getUseSandbox());

              InfoServiceInterface infoService = user.getService(AdWordsService.V201109.INFO_SERVICE);


              InfoSelector selector = new InfoSelector();
              selector.setApiUsageType(ApiUsageType.UNIT_COUNT_FOR_CLIENTS);
              String today = new SimpleDateFormat("yyyyMMdd").format(new Date());
              selector.setDateRange(new DateRange(today, today));
              selector.setIncludeSubAccounts(true);

              ApiUsageInfo apiUsageInfo = infoService.get(selector);
              for (ApiUsageRecord record : apiUsageInfo.getApiUsageRecords()) {
                      ......

但是 apiUsageInfo.getApiUsageRecords 只返回我的一些 clientId。 你有什么建议吗?

【问题讨论】:

    标签: google-ads-api


    【解决方案1】:

    我的回答将对 PHP 开发者有所帮助

    我正在使用 v201502(php),您将从ManagedCustomerService api 获取所有帐户详细信息。请参考以下网址https://developers.google.com/adwords/api/docs/reference/v201502/ManagedCustomerService

    这是我使用的示例代码,

        function DisplayAccountTree($account, $link, $accounts, $links, $depth) {
          print str_repeat('-', $depth * 2);
          printf("%s, %s\n", $account->customerId, $account->name);
          if (array_key_exists($account->customerId, $links)) {
            foreach ($links[$account->customerId] as $childLink) {
              $childAccount = $accounts[$childLink->clientCustomerId];
              DisplayAccountTree($childAccount, $childLink, $accounts, $links,
                  $depth +1);
            }
          }
        }
        function GetAccountHierarchyExample(AdWordsUser $user) {
          // Get the service, which loads the required classes.
    
          $user->SetClientCustomerId('xxx-xxx-xxxx');
          $managedCustomerService =
              $user->GetService('ManagedCustomerService');
    
          // Create selector.
          $selector = new Selector();
          // Specify the fields to retrieve.
          $selector->fields = array('CustomerId',  'Name');
    
          // Make the get request.
          $graph = $managedCustomerService->get($selector);
    
          // Display serviced account graph.
          if (isset($graph->entries)) {
            // Create map from customerId to parent and child links.
            $childLinks = array();
            $parentLinks = array();
            if (isset($graph->links)) {
              foreach ($graph->links as $link) {
                $childLinks[$link->managerCustomerId][] = $link;
                $parentLinks[$link->clientCustomerId][] = $link;
              }
            }
            // Create map from customerID to account, and find root account.
            $accounts = array();
            $rootAccount = NULL;
            foreach ($graph->entries as $account) {
              $accounts[$account->customerId] = $account;
              if (!array_key_exists($account->customerId, $parentLinks)) {
                $rootAccount = $account;
              }
            }
            // The root account may not be returned in the sandbox.
            if (!isset($rootAccount)) {
              $rootAccount = new Account();
              $rootAccount->customerId = 0;
            }
            // Display account tree.
            print "(Customer Id, Account Name)\n";
            DisplayAccountTree($rootAccount, NULL, $accounts, $childLinks, 0);
          } else {
            print "No serviced accounts were found.\n";
          }
        }
    
        GetAccountHierarchyExample($user);
    

    SetClientCustomerId 将是您所有帐户的父 ID,它将显示在您的 google AdWords 帐户的退出按钮附近,请参阅附图

    我希望这个答案会有所帮助,如果您需要任何进一步的帮助,请在下面添加您的 cmets

    【讨论】:

      【解决方案2】:

      如果您只需要 clientCustomerIds 列表,请尝试 ServicedAccountService。
      Here 是一个代码示例,说明了如何完成此操作。

      下次,您可能还想考虑在 AdWords API 官方论坛上提问:https://groups.google.com/forum/?fromgroups#!forum/adwords-api

      【讨论】:

      • code.google.com 链接不再有效。 @Anash:你能发布更新的链接吗?
      猜你喜欢
      • 1970-01-01
      • 2019-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多