2012-06-20 7 views
2

내 고객 센터 계정에서 모든 고객 ID를 검색하고 싶습니다. 이 코드를 사용하고 있습니다.내 고객 센터 계정의 모든 고객 ID 가져 오기 adwordsAPI

   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는 내 일부 클라이언트 ID 만 반환합니다. 제안 사항이 있습니까?

답변

1

clientCustomerIds 목록 만 있으면 필요한 경우 ServicedAccountService를 시도하십시오.
Here은이 작업을 수행하는 방법을 보여주는 코드 예제입니다.

다음에, 당신은 또한 애드워즈 API에 대한 공식 포럼에 질문을 고려하는 것이 좋습니다 : https://groups.google.com/forum/?fromgroups#!forum/adwords-api

+2

code.google.com 링크가 더 이상 작동하지 않습니다. @Anash : 업데이트 된 링크를 게시 할 수 있습니까? – Taher

3

내 대답은 PHP 개발자를위한 도움이 될 것입니다

내가 v201502 (PHP)를 사용하고 있습니다 , 모든 계정 세부 사항을 ManagedCustomerService api에서 얻을 수 있습니다.

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); 

귀하의 모든 계정의 상위 ID가됩니다을 SetClientCustomerId

다음 URL https://developers.google.com/adwords/api/docs/reference/v201502/ManagedCustomerService

이 내가 사용하는 샘플 코드를 참조하십시오, 그것은 당신이 구글의 로그인 아웃 버튼 근처에 등장한다 애드워즈 계정 enter image description here

나는이 답변이 도움이 될 것입니다 희망 첨부 된 이미지를 참조하십시오, 아래에 의견 당신이 경우 w 추가하십시오 개미 더 이상 도움이