简体   繁体   中英

How to get lead details without API details?

I followed the instructions here and getting real time updates. But problem is how can I get lead details using this code:

use FacebookAds\Object\Lead;

$form = new Lead(<LEAD_ID>); 
$form->read();

When I am using Leadgen ID then getting error: Fatal error: Uncaught InvalidArgumentException: An Api instance must be provided as argument or set as instance in the...

But if I use:

use FacebookAds\Api;
use FacebookAds\Object\Lead;

Api::init(
    'appid', 
    'secret_token',
    $_SESSION['facebook_access_token'] 
);

$form = new Lead('leadgenid');
$form->read();

Then I am getting data as I want:

{
    "created_time": "2015-02-28T08:49:14+0000", 
    "id": "<LEAD_ID>", 
    "ad_id": "<AD_ID>",
    "form_id": "<FORM_ID>",
    "field_data": [{
        "name": "car_make",
        "values": [
            "Honda"
        ]
    }, {
        "name": "full_name", 
        "values": [
            "Joe Example"
        ]
    }, {
        "name": "email", 
        "values": [
            "joe@example.com"
        ]
    }]
}

But user_access_token expired after 2 months(long_lived token)

what is the best way to setup an API on our Server which we connect via webhook to receive LeadAd data and store it in our database automatically? Do we have to create a new token every two month manually? is there any better way?

There is "system user" in facebook ads platform that should be the answer to your question. Please find its details below: https://developers.facebook.com/docs/marketing-api/businessmanager/systemuser/v2.5

In brief, by using a system user, you will be able to generate a token that does not require user to sign in every certain period. However, you will need to have an app that has standard access in order to be able to create a system user in your business manager.

Hope that it helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM