我想通过account id获取我当前账户下的子账户树,按照examples方法获取,响应一个空对象。事实上,该账号已经绑定了7个子账号。
https://github.com/googleads/googleads-adsense-examples/blob/master/php-clientlib-1.x/v1.x/examples/GetAccountTree.php
$pageToken = null;
$optParams['maxResults'] = 500;
$optParams['pageToken'] = $pageToken;
$result = $this->service->accounts->listAccounts($optParams);
$accounts = null;
if (!empty($result['items'])) {
$accounts = $result['items'];
foreach ($accounts as $account) {
$this->account_id = $account['id'];
}
}
$subAccounts = $this->service->accounts->get($this->account_id, array('tree' => true));
if (!empty($subAccounts['subAccounts'])){
foreach ($subAccounts['subAccounts'] as $account) {
dump($account);
}
}
dd($subAccounts);
回复:
Google_Service_AdSense_Account^ {#1363
#collection_key: "subAccounts"
#internal_gapi_mappings: array:1 [
"creationTime" => "creation_time"
]
+creationTime: "1551266190244"
+id: "pub-*********"
+kind: "adsense#account"
+name: "*********"
+premium: false
#subAccountsType: "Google_Service_AdSense_Account"
#subAccountsDataType: "array"
+timezone: "Europe/London"
#modelData: array:1 [
"creation_time" => "1551266190244"
]
#processed: []
}
如果我转储,会有一个奇怪的问题dd($subAccounts,$subAccounts['subAccounts']);
回复:
Google_Service_AdSense_Account^ {#1363
#collection_key: "subAccounts"
#internal_gapi_mappings: array:1 [
"creationTime" => "creation_time"
]
+creationTime: "1551266190244"
+id: "pub-*********"
+kind: "adsense#account"
+name: "*********"
+premium: false
#subAccountsType: "Google_Service_AdSense_Account"
#subAccountsDataType: "array"
+timezone: "Europe/London"
#modelData: array:2 [
"creation_time" => "1551266190244"
"subAccounts" => []
]
#processed: array:1 [
"subAccounts" => true // not empty
]
}