gpt4 book ai didi

google-ads-api - 通过 adwords API 从 MCC adwords 帐户获取所有客户 ID

转载 作者:行者123 更新时间:2023-12-04 18:18:54 26 4
gpt4 key购买 nike

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

最佳答案

我的回答将对 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 帐户的退出按钮附近,请参阅附图

enter image description here

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

关于google-ads-api - 通过 adwords API 从 MCC adwords 帐户获取所有客户 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11124700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com