获取帐户子帐户树为空

时间:2019-08-07 12:08:31

标签: php google-api-php-client adsense adsense-api

我想通过帐户ID获取当前帐户下的子帐户树,并根据示例方法获取它,并响应一个空对象。实际上,该帐户已绑定到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
  ]
}

0 个答案:

没有答案