Facebook 广告 API:adaccounts 字段已弃用 v2.11 及更高版本

Facebook Ads API: adaccounts field is deprecated for versions v2.11 and higher

我正在尝试通过 Facebook 广告 SDK 获取所有广告帐户。我会收到以下错误

这是我的代码。

public function getAdAccounts() {
        $user = new AdAccountUser('**************');
        $user->read(array(AdAccountUserFields::ID));

        $accounts = $user->getAdAccounts();

        // Print out the accounts
        echo "Accounts:\n";
        foreach($accounts as $account) {
          echo $account->id . ' - ' .$account->name."\n";
        }

        // Grab the first account for next steps (you should probably choose one)
        $account = (count($accounts)) ? $accounts->getObjects()[0] : null;
        echo "\nUsing this account: ";
        echo $account->id."\n";
    }

我通过 explorer 进行了尝试,它有效。

您可以使用 User class,例如:

use FacebookAds\Object\User;

....

$fields = [
    'name',
];

$user = new User($id);

$accounts = $user->getAdAccounts($fields);

// Print out the accounts
echo "Accounts:\n";
foreach($accounts as $account) {
    echo $account->id . ' - ' .$account->name."\n";
}

你也可以看看example here