skip to Main Content

I am using php code for fb marketing api and facing this deprecation issue

Deprecated: read is being deprecated, please try not to use this in new code.

use FacebookAdsObjectAdAccount;
use FacebookAdsObjectFieldsAdAccountFields;

$account = new AdAccount('act_<AD_ACCOUNT_ID>');
$account->read(array(
  AdAccountFields::TOS_ACCEPTED,
));

// Dump TOS Accepted info.
var_dump($account->{AdAccountFields::TOS_ACCEPTED});

Have they updated their code somewhere else? what should I use instead of read function? Thanks.

2

Answers


  1. The API successfully return the field about TOS, probably a deprecation of the SDK Library, try this (I take it from an example in the repo):

    use FacebookAdsObjectAdAccount;
    use FacebookAdsApi;
    use FacebookAdsLoggerCurlLogger;
    $access_token = '<ACCESS_TOKEN>';
    $app_secret = '<APP_SECRET>';
    $app_id = '<APP_ID>';
    $id = '<AD_ACCOUNT_ID>';
    $api = Api::init($app_id, $app_secret, $access_token);
    $api->setLogger(new CurlLogger());
    $fields = array(
      'name',
      'tos_accepted',
    );
    $params = array(
    );
    echo json_encode((new AdAccount($id))->getSelf(
      $fields,
      $params
    )->exportAllData(), JSON_PRETTY_PRINT);
    
    Login or Signup to reply.
  2. The read function is deprecated from the SDK

    You should use the getSelf instead of this.

    They have mentioned this in the sdk files on line 277 of https://github.com/facebook/facebook-php-business-sdk/blob/master/src/FacebookAds/Object/AbstractCrudObject.php

      /**
       * @deprecated
       * use getSelf() instead
       * Read object data from the graph
       *
       * @param string[] $fields Fields to request
       * @param array $params Additional request parameters
       * @return $this
       */
    
      public function read(array $fields = array(), array $params = array()) {
       .....
      }
    

    You can find documentation related to other deprecated functions over there.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search