Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I get Ad Report Stats via the SDK? #14

Closed
la-bas opened this issue Aug 25, 2014 · 6 comments
Closed

How do I get Ad Report Stats via the SDK? #14

la-bas opened this issue Aug 25, 2014 · 6 comments

Comments

@la-bas
Copy link

la-bas commented Aug 25, 2014

I can't figure out how to make calls to reportstats using the SDK.
The class AdAccount do have a method named getReportsStats() which takes an array of fields and an array of parameters as arguments, so I tried something like this:

    $fields = array('account_id', 'total_actions', 'spend'); // The fields I ask for?
    $params = array(
        'data_columns' => array (
            'account_id',
            'total_actions',
            'spend'
        ),
        'date_preset' => 'last_7_days',
    );

    $account = new AdAccount('act_' . $accountID);
    $account->getReportsStats($fields, $params);
    return json_encode($account->getData());        

However this just returns the ad account data, not the actual stats.
When I examined the object $account after the call to getReportsStats() method I found that it did indeed contain the stats. Still getData() doesn't return it. Am I supposed to use some other method to get the stats?

@la-bas
Copy link
Author

la-bas commented Aug 25, 2014

Sorry, now I've got it.
If anyone else ever gets as confused as I was, this is the solution:

    $account = new AdAccount('act_' . $accountID);
    $reports = $account->getReportsStats($fields, $params);
    $response = array();
    foreach($reports as $report) {
        $response[] = $report->getData();
    }

    return json_encode($response);  

@la-bas la-bas closed this as completed Aug 25, 2014
@paulbain
Copy link
Contributor

it looks like you're doing a lot of work to just get the json again, you may want to think about something like:

$json = $reports->getResponse()->getRawResponse(); 

@la-bas
Copy link
Author

la-bas commented Aug 28, 2014

Thanks, much better!

@siegerhansma
Copy link

I am using the same code as la-bas but I'm greeted with a permission error. It seems I can't reach reports as an Analyst account while I can reach the reports via the Ads Manager. What's the difference between calling them in the browser and calling them in code?

Error:
This Ads API call requires the user to be admin of the ad account. User xxxxxxxxxxxx not admin on ad account xxxxxxxxxxxxxxxxxxxxx.

@paulbain
Copy link
Contributor

@siegerhansma, please create a new issue with the exact series of requests your using and we can look into it

@paulbain
Copy link
Contributor

paulbain commented Dec 6, 2014

The SDK requires PHP 5.4 and above so this is why you see these errors.

Sent from my iPhone

On Dec 5, 2014, at 7:55 PM, sandy69 notifications@github.com wrote:

I am getting PHP Parse error: syntax error, unexpected T_USE, expecting T_FUNCTION in /FacebookAds/Object/AdAccount.php on line 34

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.

array ( 'account_id', 'total_actions', 'spend' ), 'date_preset' => 'last_7_days', ); $account = new AdAccount('act_' . $accountID); $account->getReportsStats($fields, $params); return json_encode($account->getData()); ?>


Reply to this email directly or view it on GitHub.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants