2

我想从我的 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。你有什么建议吗?

4

2 回答 2

3

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

我正在使用 v201502(php),您将从ManagedCustomerServiceapi 获取所有帐户详细信息。请参考以下网址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 帐户的退出按钮附近,请参阅附图

在此处输入图像描述

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

于 2015-05-27T10:44:31.483 回答
1

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

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

于 2012-06-27T05:25:30.930 回答