Facebook Ads API:版本v2.11及更高版本不建议使用adaccounts字段

时间:2018-11-28 11:45:54

标签: php facebook facebook-graph-api facebook-ads-api

我正在尝试通过Facebook Ads SDK提取所有广告帐户。我发现以下错误 enter image description here

这是我的代码。

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进行了尝试,并且可以正常工作。 enter image description here

1 个答案:

答案 0 :(得分:1)

您可以使用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