I'm currently working on an app, with a system user that have access to both Page and AdAccount that I'm querying. I got an access token with all the Permissions that I could query (because I had to try everything I could) :
read_insights, publish_video, catalog_management, pages_manage_instant_articles, pages_show_list, read_page_mailboxes, ads_management, ads_read, business_management, pages_messaging, instagram_basic, instagram_manage_comments, leads_retrieval, whatsapp_business_management, attribution_read, pages_read_engagement, pages_manage_metadata, pages_read_user_content, pages_manage_ads, pages_manage_posts, pages_manage_engagement, public_profile
I am able to get all leadgen_forms, but then when I want to query the leads of these forms, the Facebook API sends me empty data arrays.
The code :
<?php
namespace App\Connecteurs;
use App\Repository\ClientRepository;
use Doctrine\ORM\EntityManagerInterface;
use Facebook\Facebook;
class FacebookGraphConnecteur
{
const APP_ID = 'XXXXXXXXXXX';
const APP_SECRET = 'XXXXXXXXXXX';
const ACCESS_TOKEN = 'XXXXXXXXXXXX';
private $fb;
private $em;
public function __construct(EntityManagerInterface $em)
{
$this->fb = new Facebook(
[
'app_id' => self::APP_ID,
'app_secret' => self::APP_SECRET,
'default_access_token' => self::ACCESS_TOKEN,
]
);
$this->em = $em;
}
public function recupereLeads()
{
$clients_ids = $this->recupereFacebookAdsIdClients();
foreach ($clients_ids as $client_ids) {
$token = $this->fb->get("/{$client_ids['facebookAdsId']}?fields=access_token")->getGraphNode()->asArray();
$response = $this->fb->get("/{$client_ids['facebookAdsId']}/leadgen_forms", $token['access_token']);
$params['access_token'] = $token['access_token'];
$forms = $response->getDecodedBody()["data"];
$leads = [];
foreach ($forms as $form) {
if ($form["status"] === "ACTIVE") {
$formId = $form['id'];
$leadsForm = $this->fb->get("/{$formId}/leads?fields=created_time,id,ad_id,form_id,field_data", self::ACCESS_TOKEN);
$leads[] = $leadsForm->getDecodedBody()["data"];
}
}
var_dump($leads);
}
}
private function recupereFacebookAdsIdClients()
{
$em = $this->em;
/** @var ClientRepository $repo */
$repo = $em->getRepository("App:Client");
return $repo->recupereFacebookAdsId();
}
}
The result :
array(16) {
[0]=>
array(0) {
}
[1]=>
array(0) {
}
[2]=>
array(0) {
}
[3]=>
array(0) {
}
//.... And so on
}
The /<FORM_ID>/leads endpoint give me 200 http code though :

I also tryed with the Business SDK, but got the same result :
$leads[] = json_encode((new LeadgenForm($formId))->getLeads(
$fields,
$params
)->getResponse()->getContent(), JSON_PRETTY_PRINT);
I also saw that from the v.9.0, we could not get prospect if the app is in development mode (what it is), but I also saw that there were no development / live mod anymore... I'm really confused.
What am I doing wrong ?
Thank you very much for your help !