Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

186
Views
Get all lead ads form facebook API

I am trying to get all lead generation forms in my PHP script using Facebook API version 9.0

I am making the request like this:

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

But its returning error, saying

{
   "error": {
      "message": "(#12) leadgen_forms field is deprecated for versions v5.0 and higher",
      "type": "OAuthException",
      "code": 12,
      "fbtrace_id": "ARMp3WCko2raN5521458h"
   }
}

If I change the version in the above request, it says:

You are calling a deprecated version of the Ads API. Please update to the latest version: v9.0.

UPDATE:

Here's the SDK function which i am using to get Lead Generation Forms:

public function getLeadGenForms(array $fields = array('first_name', 'last_name'), array $params = array(), $pending = false) {
    $this->assureId();

    $param_types = array(
      'query' => 'string',
    );
    $enums = array(
    );

    $request = new ApiRequest(
      $this->api,
      $this->data['id'],
      RequestInterface::METHOD_GET,
      '/leadgen_forms',
      new LeadgenForm(),
      'EDGE',
      LeadgenForm::getFieldsEnum()->getValues(),
      new TypeChecker($param_types, $enums)
    );
    $request->addParams($params);
    $request->addFields($fields);
    return $pending ? $request : $request->execute();
  }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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).

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!