我正在尝试通过Facebook Ads 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进行了尝试,并且可以正常工作。
答案 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。