skip to Main Content

I get this error when I try to run my app locally via xampp. Just to note, I generated code using quick start from developers.facebook so there shouldnt be errors within the code itself.

Notice: Use of undefined constant STDOUT – assumed ‘STDOUT’ in C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsLoggerCurlLogger.php on line 83

Warning: fwrite() expects parameter 1 to be resource, string given in C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsLoggerCurlLogger.php on line 182

Fatal error: Uncaught exception ‘FacebookAdsHttpExceptionAuthorizationException’ with message ‘(#100) Filtering field delivery_info is invalid. Please refer to the document https://developers.facebook.com/docs/marketing-api/insights for valid filters.’ in C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsHttpExceptionRequestException.php:144 Stack trace: #0 C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsHttpClient.php(215): FacebookAdsHttpExceptionRequestException::create(Object(FacebookAdsHttpResponse)) #1 C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsHttpRequest.php(282): FacebookAdsHttpClient->sendRequest(Object(FacebookAdsHttpRequest)) #2 C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsApi.php(162): FacebookAdsHttpRequest->execute() #3 C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsApi.php(204): FacebookAdsApi->executeRequest(Object(FacebookAdsHttpRequest)) #4 C:xampphtdocsworkingvendorfacebo in C:xampphtdocsworkingvendorfacebookphp-ads-sdksrcFacebookAdsHttpExceptionRequestException.php on line 144

I’m starting to suspect that I got the wrong files from the composer. or there might be a problem with my setup. The contents of my composer.json just before I ran composer.phar was

{
“require”: {
“facebook/php-sdk-v4” : “~5.0”,
“facebook/php-ads-sdk”: “2.10.*”
}
}

I’m going to attach the code below just in case you guys want to look at it as well. The only thing that I modified there is adding the app_id since it was not included from the generated code.

<?php
require __DIR__ . '/vendor/autoload.php';

use FacebookAdsObjectAdAccount;
use FacebookAdsObjectAdsInsights;
use FacebookAdsApi;
use FacebookAdsLoggerCurlLogger;

$app_id = '274807576345457';
$access_token = 'EAAD575ZC4O3EBAChoTmxC0nwdbvjXLRUKGGXgmZA6HZBFjmKZB6F3olMIe2mG2dgQSb9SudtN7EeeO8gzo7zgFZB0EHZAwTrg4wsIKsJxB3bhw5fonZC3YCZA0C4InaCSOgW42i4PswQa3BZCctMZBYTh94TwGLxGg8gZAZAj4zZC5PfgXl0kw6eOuxW4g1L41NOwtRDGS7O7FsJZBWZCM0IAe00WSf';
$ad_account_id = 'act_113902719358005';
$app_secret = 'aeb42f19e0f33f0937c023fff12909c4';

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

$fields = array(
  'cost_per_result',
  'cost_per_total_action',
  'cpm',
  'cpp',
  'frequency',
  'impressions',
  'impressions_auto_refresh',
  'impressions_gross',
  'reach',
  'relevance_score:score',
  'relevance_score:positive_feedback',
  'relevance_score:negative_feedback',
  'result_rate',
  'results',
  'social_impressions',
  'social_reach',
  'spend',
  'today_spend',
  'total_actions',
  'total_unique_actions',
  'actions:video_view',
  'video_10_sec_watched_actions:video_view',
  'delivery',
);
$params = array(
  'level' => 'campaign',
  'filtering' => array(array('field' => 'delivery_info','operator' => 'IN','value' => array('active','limited'))),
  'breakdowns' => array(),
  'time_range' => array('since' => '2017-09-28','until' => '2017-09-29'),
);
echo json_encode((new AdAccount($ad_account_id))->getInsights(
  $fields,
  $params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);

2

Answers


  1. if comment this part

    [json_encode((new AdAccount($ad_account_id))->getInsights(
      $fields,
      $params
    )->getResponse()->getContent(), JSON_PRETTY_PRINT);]
    

    ; the error stop.

    if make [var_export((new AdAccount($ad_account_id));] show full array

    Login or Signup to reply.
  2. I experienced the exact same error. I believe (in my case) this was because I was also using an older PHP version (5.6) resulting in some compatibility issues.

    I solved this by changing the version of php-ads-sdk from 2.8 to "8.*" (or change it to any recent version according to when you are reading this solution) in composer.json.

    Then call sudo composer update in your terminal

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search