Closed sandy69 closed 9 years ago
Hey @sandy69, have you tried going through the README file and following the steps there? https://github.com/facebook/facebook-php-ads-sdk/blob/master/README.md
AdAccount
object using use FacebookAds\Object\AdAccount;
instead of require_once
Here's more about info about composer: https://getcomposer.org/
Thank you. I didn't read the README File. Sorry. Let me try and will definitely let you know whether I am successful or not. Again Thanks for your help.
No problem. Definitely let me know :)
Hello,
I upgraded to php version 5.4.36. Installed the composer and installed the The Facebook Ads API SDK and even after that, when I execute the php script, I get the below error
PHP Fatal error: Class 'FacebookAds\Object\AdAccount' not found in /tmp/vendor/facebook/php-ads-sdk/src/FacebookAds/fb.php on line 3
PHP Code
<?php use FacebookAds\Object\AdAccount; $account = new AdAccount(); $account->name = 'act_5291585038833333'; echo $account->name;
$params = array( 'date_preset'=>'last_28_days', 'data_columns'=>"['adgroup_id','actions','spend']", );
$stats = $account->getReportsStats(null, $params);
foreach($stats as $stat) { echo $stat->impressions; echo $stat->actions; }
any information will be highly appreciated
hi @sandy69,
your script doesn't include the composer autoloader:
//
Also take note that 'act_5291585038833333' is not the account name but the id: Please take a look at this gist: https://gist.github.com/pruno/de102291ddc7539b0583/revisions
If you have any other inherent query, feel free to reply here, i'll will reopen if necessary.
Hi,
Thanks for your reply. I made the changes, as you said.
require_once( '/tmp/vendor/autoload.php' );
use FacebookAds\Object\AdAccount;
$account = new AdAccount(); $account->name = 'pinger'; echo $account->name;
Now, I get a different error
PHP Fatal error: Uncaught exception 'InvalidArgumentException' with message 'An Api instance must be provided as argument or set as instance in the \FacebookAds\Api' in /tmp/vendor/facebook/php-ads-sdk/src/FacebookAds/Object/AbstractCrudObject.php:105 Stack trace:
thrown in /tmp/vendor/facebook/php-ads-sdk/src/FacebookAds/Object/AbstractCrudObject.php on line 105
Thank you.
From: pruno [mailto:notifications@github.com] Sent: Wednesday, January 07, 2015 6:36 AM To: facebook/facebook-php-ads-sdk Cc: Sree Iyer Subject: Re: [facebook-php-ads-sdk] Ads Report Stats Error (#51)
hi @sandy69https://github.com/sandy69,
your script doesn't include the composer autoloader:
// is the dir in which your composer.json is stored include .'/vendor/autoload.php';
Also take note that 'act_5291585038833333' is not the account name but the id: Please take a look at this gist: https://gist.github.com/pruno/de102291ddc7539b0583/revisions
If you have any other inherent query, feel free to reply here, i'll will reopen if necessary.
— Reply to this email directly or view it on GitHubhttps://github.com/facebook/facebook-php-ads-sdk/issues/51#issuecomment-69029344.
hi @sandy69,
you also need to initialize the SDK.
i've updated the gist with the necessary code: https://gist.github.com/pruno/de102291ddc7539b0583/revisions
You can obtain your APP_ID and APP_SECRET from https://developers.facebook.com/apps/ And generate a token from https://developers.facebook.com/tools/explorer/ (remember to select the same app form the select input on top)
Also remember to set your ad_account id:
$account = new AdAccount('act_5291585038833333');
I am getting PHP Parse error: syntax error, unexpected T_USE, expecting T_FUNCTION in /FacebookAds/Object/AdAccount.php on line 34
I am on PHP Version 5.3.5
Below is the PHP Code, where I am accessing the class. Please let me know, if you see any issues with the code. I am not a PHP Expert. Thanks.
<?php
require_once "FacebookAds/Object/AdAccount.php";
$account =529158; $fields = array('account_id', 'total_actions', 'spend');
$params = array( 'data_columns' => array ( 'account_id', 'total_actions', 'spend' ), 'date_preset' => 'last_7_days', );
$account = new AdAccount('act_' . $accountID); $reports = $account->getReportsStats($fields, $params); $response = array(); foreach($reports as $report) { $response[] = $report->getData(); } return json_encode($response);
?>