Facebook API: Can't retrieve Facebook Lead Ads -


i have set webhook point callback url , receives following example data:

array ( [object] => page [entry] => array     (         [0] => array             (                 [id] => 297269987142139                 [time] => 1454876106                 [changes] => array                     (                         [0] => array                             (                                 [field] => leadgen                                 [value] => array                                     (                                         [ad_id] => 410908499427                                         [adgroup_id] => 238113717077                                         [created_time] => 1454847306                                         [form_id] => 577581087825                                         [leadgen_id] => 441393665441                                         [page_id] => 297269987142139                                     )                             )                     )             )     )  ) 

but if try retrieve data associated leadgen_id explained facebook, doesn't work:

 use facebookads\object\lead;   $form = new lead('441393665441');  $form->read(); 

i following error: unsupported request. please read graph api documentation @ https://developers.facebook.com/docs/graph-api

i've tried can't figure out why doesn't work.

i sending test leads this:

    curl \     -f "object_id=<page_id>" \     -f "object=page" \     -f "field=leadgen" \     -f "access_token=<access_token>" \     -f 'custom_fields={"page_id": <page_id>}' \     "https://graph.facebook.com/<api_version>/<app_id>/subscriptions_sample" 

i struggled working, , seems nobody has made copy-and-paste solution seemed work.

this php function works me:

function getlead($leadgen_id,$user_access_token) {     //fetch lead info fb api     $graph_url= 'https://graph.facebook.com/v2.5/'.$leadgen_id."?access_token=".$user_access_token;     $ch = curl_init();     curl_setopt($ch, curlopt_url, $graph_url);     curl_setopt($ch, curlopt_header, 0);     curl_setopt($ch, curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_ssl_verifypeer, 0);     $output = curl_exec($ch);      curl_close($ch);      //work lead data     $leaddata = json_decode($output);     $lead = [];     for($i=0;$i<count($leaddata->field_data);$i++) {         $lead[$leaddata->field_data[$i]->name]=$leaddata->field_data[$i]->values[0];     }     return $lead; } 

you can use function sample code:

//take input facebook webhook request $input = json_decode(file_get_contents('php://input'),true); $leadgen_id = $input["entry"][0]["changes"][0]["value"]["leadgen_id"];  //token - must generate in fb api explorer - tip: exchange long-lived (valid 60 days) token $user_access_token = 'tokenid';  //get lead info $lead = getlead($leadgen_id,$user_access_token);//get lead info 

from here on can example send realtime mail getting attributes , values in lead:

//create email lead info $mail="<html><body><h2>new lead</h2><blockquote>"; $mail.="lead id: ".$leadgen_id."<br>"; foreach($lead $attr=>$val) {     $mail.=$attr.": ".$val."<br>"; } $mail.="</blockquote></body></html>"; 

i hope helps. notice subscriptions_sample lead doesn't contain fields. can test own facebook profile real data.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -