Reputation: 53
When trying to use the Facebook Marketing API I'm getting the error "you are calling a deprecated version of the Ads API. Please update to the latest version: v2.6.' even though on all code I'm using version 2.6.
This is my code: (I've got the correct values in where the # is.
<!DOCTYPE HTML>
<html lang = "en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title> Home </title>
</head>
<body>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '#',
xfbml : true,
version : 'v2.6'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<?php
require_once('vendor/autoload.php');
use FacebookAds\Api;
use FacebookAds\Object\AdUser;
use FacebookAds\Object\AdAccount;
// Initialize a new Session and instanciate an Api object
Api::init("#", "#", "#");
// The Api object is now available trough singleton
$api = Api::instance();
$me = new AdUser('me');
$my_adaccount = $me->getAdAccounts()->current();
print_r($my_adaccount->getData());
?>
Upvotes: 2
Views: 6212
Reputation: 482
I also encountered the same problem when using java to access the Facebook marketing API. At that time, I did not find the relevant jar package in the manven warehouse, and the version on GitHub was not v12.0
But later, I saw that after their jar version was upgraded to v12.0, GIT cloned a code, packaged it and put it into its own project. It was found that the request could succeed
Upvotes: 0
Reputation: 43
You can also use setDefaultGraphVersion() method in API class(Api.php) to set version of api to call.
<?php
require_once('vendor/autoload.php');
use FacebookAds\Api;
use FacebookAds\Object\AdUser;
use FacebookAds\Object\AdAccount;
// Initialize a new Session and instanciate an Api object
Api::init("#", "#", "#");
// The Api object is now available trough singleton
$api = Api::instance();
$api->setDefaultGraphVersion("2.6");
$me = new AdUser('me');
$my_adaccount = $me->getAdAccounts()->current();
print_r($my_adaccount->getData());
?>
Upvotes: 2
Reputation: 7409
Based on one of your comments, you are using
facebook/php-ads-sdk
version 2.5. As the error mentions, you should update to 2.6 from composer.
On your project's root, change composer.json where is says:
{
"require": {
"facebook/php-ads-sdk": "2.5.*"
}
}
to
{
"require": {
"facebook/php-ads-sdk": "2.6.*"
}
}
And reinstall your dependancies by deleting your vendor folder and re-running $ composer install
to pull download it with the updated dependancies.
You've included v2.6
in your JavaScript, but this will not affect anything done with PHP.
The docs appear to be out of date on the README on Github, but there is an issue hinting that updating to 2.6 should solve the problem.
Upvotes: 2