Mike Ivars
Mike Ivars

Reputation: 21

Unsupported get request - Facebook Ads API with Facebook-PHP-Ads-SDK

When I try to use the Facebook Marketing API I'm getting always the error:

Unsupported get request

I have last version of API v2.10 installed with composer in CodeIgniter, a test app in the same version, an extended new long-lived access token that will never expire, and I use 'act_' before account_id number, but it is not working. The app is approved for Basic access level.

This is my code (extracted from sample code I get of https://developers.facebook.com/apps/MY_APP_ID/marketing-api/):

$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());

$fields = array(
    'account_id',
    'campaign_group_id',
    'campaign_group_name',
    'reach',
    'cost_per_result',
    'spend',
    'impressions',
    'total_actions',
    'clicks',
    'results',
    'actions:like',
    'actions:post_engagement',
);
$params = array(
    'time_range' => array('since' => '2017-08-09','until' => '2017-08-16'),
    'filtering' => array(),
    'level' => 'campaign',
    'breakdowns' => array('days_1'),
);
echo json_encode((new AdAccount($account_id))->getInsights(
    $fields,
    $params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);

I have read this previous articles in StackOverflow:

Upvotes: 1

Views: 1176

Answers (1)

Kint
Kint

Reputation: 133

I don't see that sample code based on your url (swapping out with my app id), but when I run your code, I don't get the unsupported get error - instead, I get:

Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: (#100) breakdowns[0]

When I comment the 'breakdowns' out, I get:

PHP Fatal error: Uncaught FacebookAds\Http\Exception\AuthorizationException: (#100) results is not valid for fields param. please check https://developers.facebook.com/docs/marketing-api/reference/ads-insights/ for all valid values

When I comment out all the invalid fields, the code works.

Upvotes: 0

Related Questions