anu
anu

Reputation: 41

PHP Fatal error: Class 'FacebookAds\Object\AdAccount' not found in

I am using Facebook Ads API to pull data from ads Reporting. Below is my code :

<?php

use FacebookAds\Object\AdAccount;

$account = new AdAccount('act_xxxx');

$params = array(
    'date_preset'=>'last_28_days',
    'data_columns'=>"['adgroup_id']",
);

$stats = $account->getReportsStats(null, $params);


foreach($stats as $stat) {
    echo "is it inside the foreach loop \n";
    echo $stat->impressions;
    echo $stat->actions;
}
?>

I get FacebookAds/Object/AdAccount not found. I checked the path and everything looks correct. any idea, what could be the reason for this error. I am not a PHP Expert, so please do correct me, if something is wrong with my code.

Upvotes: 0

Views: 2083

Answers (1)

Achal Saraiya
Achal Saraiya

Reputation: 409

<?php
function __autoload($class) { 
    require_once $class.".php";
}

Save this file as autoload.php in same directory then add below code at start

<?php
require_once('./autoload.php');

Explanation:

In your code you haven't included the file which contains the class FacebookAds\Object\AdAccount. That's why it gives class not found error.

Above code will make sure that all necessary class files are include in code.

Upvotes: 1

Related Questions