Head over to developer.facebook.com and create an App
On your server, create a facebook webhook that will handle facebook calls. Then create a "leadgen" webhook on you App: https://developers.facebook.com/docs/graph-api/webhooks/v2.6
Get lifetime access token to App (I asked for the following permissions: manage_pages, publish_pages, publish_actions, public_profile)
Note: Token should now be listed in: https://developers.facebook.com/tools/accesstoken/
Subscribe App to Page using your access token
curl \
-F "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/v2.6/<PAGE_ID>/subscribed_apps"
Whenever a Lead is generated you'll receive a request on your facebook webhook with the following body:
{
"entry": [
{
"changes": [
{
"field": "leadgen",
"value": {
"ad_id": 0,
"form_id": 129595594131704,
"leadgen_id": 130528934038370,
"created_time": 1466583136,
"page_id": 230076207144371,
"adgroup_id": 0
}
}
],
"id": "230076207144371",
"time": 1466583137
}
],
"object": "page"
}
Now, grab the lead using the leadgen_id value:
curl -G \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/v2.6/<LEADGEN_ID>
Sample output:
{
"created_time": "2016-06-22T09:29:50+0000",
"id": "243870422662760",
"field_data": [
{
"name": "email",
"values": ["tom_cook@gmail.com"]
},
{
"name": "phone_number_(eg.65xxxxxxxx)",
"values": ["6552467291"]
},
{
"name": "full_name",
"values": ["Tom Cook"]
}
]
}