2

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 FacebookAds\Object\AdAccount;
use FacebookAds\Object\Fields\AdAccountFields;

$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.

Matteo
  • 37,680
  • 11
  • 100
  • 115
Zain Farooq
  • 2,956
  • 3
  • 20
  • 42

2 Answers2

3

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.

TheVigilant
  • 720
  • 8
  • 16
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 FacebookAds\Object\AdAccount;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
$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);
Matteo
  • 37,680
  • 11
  • 100
  • 115