代码之家  ›  专栏  ›  技术社区  ›  Manoj Dhiman

Facebook Ads API:AdaAccounts字段不适用于v2.11及更高版本

  •  1
  • Manoj Dhiman  · 技术社区  · 7 年前

    我正在尝试通过Facebook ads SDK获取所有ads帐户。我发现了以下错误 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 回复  |  直到 7 年前
        1
  •  1
  •   Matteo    7 年前

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