Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

An Api instance must be provided as argument or set as instance in the \FacebookAds\Api

i am integrating facebook marketing api and when i call to the function which contains code for creating facebook campaign but i am getting below exception "An Api instance must be provided as argument or set as instance in the \FacebookAds\Api". below is the function where exceptions occur

protected static function assureApi(Api $instance = null) {
$instance = $instance ?: Api::instance();
if (!$instance) {
  throw new \InvalidArgumentException(
    'An Api instance must be provided as argument or '.
    'set as instance in the \FacebookAds\Api');
}
return $instance;
}
like image 210
Atul Suroshe Avatar asked Oct 31 '25 23:10

Atul Suroshe


1 Answers

You must init Facebook Ads Api first:

// Add to header of your file
use FacebookAds\Api;

// Initialize a new Session and instantiate an API object
Api::init(
  '1863496587233765', // App ID
  '{your-app-secret}',
  $_SESSION['facebook_access_token'] // Your user access token
);

Then, you can start using the Api as you are.

like image 191
manelescuer Avatar answered Nov 03 '25 12:11

manelescuer