Search code examples
phpfacebook-graph-apifacebook-business-sdk

How to return all Campaign information for a specific user by calling the Facebook market API using the Facebook-business-php-sdk


I'm trying to get all campaign IDs using the supplied code from the API graph explore tool but the code supplied by the Graph API tool returns and error.

The Facebook initialization code is below

    $api = new \Facebook\Facebook([
      'app_id' => '00000',
      'app_secret' => '0000',
    ]);

When I run the following code:

      $response = $api->get(
        '/act_0000000/campaigns',
        '{Token}'
      );

The following error is returned:

You are calling a deprecated version of the Ads API. Please update to the latest version: v3.2.

Or when I update the code to match what is specified as the latest version:

 $response = $api->get(
        'v3.3/act_0000000/campaigns',
        '{Token}'
      );

Then the following error is returned:

Unknown path components: /act_00000000/campaigns

I've tried using the Raw SDK but the documentation seems to be either depreciated or not working all together. Any help or advice is greatly appreciated, I could use the cURL method but id rather use the raw SDK.


Solution

  • The way i was able to resolve the issue was by running the following code, the docs seems to only be updated on the Facebook-business-php-sdk GitHub link

    you could either manually pass the string to the AdAccount() like i id or dynamically though a for-each.

     Api::init($app_id, $app_secret, $access_token);
     Api::instance();
     $data = new AdAccount('act_00000');
     $results = $data->getCampaigns(['id', 'name']);