问题
I am working on the facebook ads API (3.2) But I am getting some weird errors. I am trying to get the campaigns
And following is the method I am using for this according to the documentation Here
public function getcampaigns() {
$adaccount = new AdAccount('331*****10774');
$campaigns = $adaccount->getCampaigns();
print_r($campaigns);
}
But I am getting the error
Then I try this with Explorer with the same access_token
and it worked well.
I am giving the following permissions in access_token
$this->permissions = ['email', 'ads_management', 'pages_show_list', 'publish_pages', 'manage_pages', 'ads_read', 'business_management'];
回答1:
You should prefix with the act_
string, so
try this:
$adaccount = new AdAccount('act_331*****10774');
instead of this:
$adaccount = new AdAccount('331*****10774');
In addition, if you test the example:
use FacebookAds\Object\AdAccount;
use FacebookAds\Api;
use FacebookAds\Logger\CurlLogger;
$id = 'act_XXXX';
$api = Api::init($app_id, $app_secret, $access_token);
$api->setLogger(new CurlLogger());
$fields = array(
'name',
'objective',
);
$params = array(
'effective_status' => array('ACTIVE','PAUSED'),
);
echo json_encode((new AdAccount($id))->getCampaigns(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);
Works as expected
Hope this help
回答2:
You need to get your APP approved by Facebook to access the permission ads_management
It will work on explorer since it's just a tool FB has provided to test and play around.
来源:https://stackoverflow.com/questions/53589105/facebook-ads-api-object-with-id-does-not-exist-cannot-be