I am programming a Marketing-API for facebook and am running into the following error:
Fatal error: Uncaught exception
'FacebookAdsHttpExceptionAuthorizationException'
with message
'(#2635) You are calling a deprecated version of the Ads API.
Please update to the latest version: v2.8.'
in [MY FOLDER]/vendor/facebook/php-ads-sdk/src/FacebookAds/Http/Exception/RequestException.php:163
Here is the file [MY FOLDER]/composer.json
I used to install the SDKs:
{
"require": {
"facebook/php-sdk-v4" : "~5.0",
"facebook/php-ads-sdk": "2.8.*"
}
}
Within the app folder (which I upload to a private server, from /localhost/~[my user name]/[some directory]/
, henceforth referred to as [MY FOLDER]
) I have two php
files index.php
and login-callback.php
as well as the sdks (facebook & facebook-ads) located in [MY FOLDER]/vendor
. Here are the php
files:
File [MY FOLDER]/index.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use FacebookFacebook;
session_start();
$fb = new Facebook([
'app_id' => '000000000000', // censored
'app_secret' => '000000000000', // censored
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['ads_management'];
$loginUrl = $helper->getLoginUrl('[MY FOLDER]/login-callback.php',$permissions);
?>
File [MY FOLDER]/login-callback.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use FacebookFacebook;
use FacebookExceptionsFacebookResponseException;
use FacebookExceptionsFacebookSDKException;
use FacebookAuthentificationAccessToken;
use FacebookAdsApi;
use FacebookAdsObjectAdUser;
use FacebookAdsObjectCampaign;
date_default_timezone_set('GMT');
session_start();
$fb = new Facebook([
'app_id' => '000000000000', // censored
'app_secret' => '000000000000', // censored
]);
$helper = $fb->getRedirectLoginHelper();
$accessToken = $helper->getAccessToken();
// This is actually wrapped in a try-catch control group
// I have left it out for this question, as there are no problems
// in this respect and the clauses are really long.
Api::init(
$app_id,
$app_key,
$_SESSION['facebook_access_token']
);
$campaign = new Campaign('000000000000'); // censored
try {
$campaign->read(array(
CampaignFields::ID,
CampaignFields::NAME,
CampaignFields::OBJECTIVE,
));
} catch(FacebookExceptionsFacebookResponseException $e) {
// error with Graph API
exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
// error with Facebook SDK
exit;
}
?>
The error occurs when trying to call $campaign->read(array(···))
. The SDK returns the error above together with the tracking:
Stack trace:
#0 [API-FOLDER]/Http/Client.php
(217): FacebookAdsHttpExceptionRequestException::create(Array, 400)
#1 [API-FOLDER]/Http/Request.php
(282): FacebookAdsHttpClient->sendRequest(Object(FacebookAdsHttpRequest))
#2 [API-FOLDER]/Api.php
(152): FacebookAdsHttpRequest->execute()
#3 [API-FOLDER]/Api.php
(194): FacebookAds
in [API-FOLDER]/Http/Exception/RequestException.php
on line 163
Here [API-FOLDER]
= [MY FOLDER]/vendor/facebook/php-ads-sdk/src
.
Note the demand in the error: …Ads API. Please update to the latest version: v2.8. But I have done this. Can someone please tell me, what on Earth is going on?
2
Answers
I have found a(n annoying) solution. I went to github and manually downloaded the latest version.
This is ridiculous. I followed the official installation instructions on https://developers.facebook.com/docs/marketing-api/sdks (create
composer.json
file incl. explicit version details —> execute terminal commandphp composer.phar install --no-dev
). I don’t see why this does not work.Has anyone else encountered this problem? Or am I one of the few, for whom automatic installation did not lead to the right version?
I think this might have to do with the login part. When initializing the Facebook class here,
you did not specify the API version to use – so it falls back to the lowest API version your app can use. Likely that messes up things later when you use the resulting token to make calls to the Marketing API.
Try and explicitly specify the API version to use,