0
votes

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:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 83

Warning: fwrite() expects parameter 1 to be resource, string given in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Logger\CurlLogger.php on line 182

Fatal error: Uncaught exception 'FacebookAds\Http\Exception\AuthorizationException' 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:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.php:144 Stack trace: #0 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Client.php(215): FacebookAds\Http\Exception\RequestException::create(Object(FacebookAds\Http\Response)) #1 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Request.php(282): FacebookAds\Http\Client->sendRequest(Object(FacebookAds\Http\Request)) #2 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(162): FacebookAds\Http\Request->execute() #3 C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Api.php(204): FacebookAds\Api->executeRequest(Object(FacebookAds\Http\Request)) #4 C:\xampp\htdocs\working\vendor\facebo in C:\xampp\htdocs\working\vendor\facebook\php-ads-sdk\src\FacebookAds\Http\Exception\RequestException.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 FacebookAds\Object\AdAccount;
use FacebookAds\Object\AdsInsights;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;

$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
Were you able to solve this? I'm encountering the exact same issueFredds

2 Answers

0
votes

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

0
votes

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