php - Get all lead ads form facebook API

one text

Solution:

This is the correct GET request URL:

https://graph.facebook.com/v9.0/<PAGE_ID>/leadgen_forms?access_token=<page_access_token>

And example use of the FB PHP SDK:

try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/<PAGE_ID>/leadgen_forms',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

Source: Generated from the Graph API Explorer.

Screenshot of a working error-free response: enter image description here

Requirements:

  • Use the page access token of the page <PAGE_ID> (not your own user token or any other page).
  • Grant the pages_show_list, pages_read_engagement and pages_manage_ads permissions to the FB app that you connect to (to get the page access token).

Source