facebookarchive / php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
Other
3.17k stars 1.96k forks source link

On real time giving Error. When we passed leadgen_id is static. its giving result(lead informations) (#803) Some of the aliases you requested do not exist: {leadgen_id} issues occur in our webhook.php page This is permission issue or any other . i have no idea. #1121

Open prashnatkumar opened 5 years ago

prashnatkumar commented 5 years ago

On real time giving Error. When we passed leadgen_id is static. its giving result(lead informations) (#803) Some of the aliases you requested do not exist: {leadgen_id} issues occur in our webhook.php page This is permission issue or any other . i have no idea.

My token scope is user_birthday, user_location, user_posts, user_gender, user_age_range, email, manage_pages, pages_manage_cta, pages_show_list, publish_pages, read_page_mailboxes, ads_management, ads_read, business_management, pages_messaging, pages_messaging_phone_number, pages_messaging_subscriptions, leads_retrieval, public_profile My app permission is

Approved Items 1.LOGIN PERMISSIONS 2.email Provides access to the person's primary email address. This permission is approved by default. 3.leads_retrieval Info people choose to share about themselves when submitting a form in an ad 4.manage_pages Enables your app to retrieve access_tokens for Pages and apps that the person administrates. 5.public_profile Provides access to a person's name and profile picture. This permission is approved by default. 6.user_friends Provides access to a person's list of friends that also use your app. Code Samples Code--> when pass leadgen_id on real time
<?php require_once 'vendor1/src/Facebook/autoload.php'; $fb = new Facebook\Facebook([ 'app_id' => {app_id}, 'app_secret' => {app_secret}, 'default_graph_version' => 'v2.4', ]); $user_access_token={user_access_token}; try { $response = $fb->get('/me',$user_access_token ); } catch(\Facebook\Exceptions\FacebookResponseException $e) { error_log(print_r($e , true)); } catch(\Facebook\Exceptions\FacebookSDKException $e) { error_log(print_r($e , true)); } $node = $response->getGraphNode(); var_dump($node->getField('id')); $input = json_decode(file_get_contents('php://input'), true); $leadgen_id = json_encode($input['entry'][0]['changes'][0]['value']['leadgen_id']); $form_id = json_encode($input['entry'][0]['changes'][0]['value']['form_id']); $page_id = json_encode($input['entry'][0]['changes'][0]['value']['page_id']);

error_log(print_r($leadgen_id , true));

$lead = getLead($leadgen_id,$user_access_token); error_log(print_r($lead , true));

function getLead($leadgen_id,$user_access_token) { //fetch lead info from FB API $graph_url= 'https://graph.facebook.com/v2.3/'.$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); error_log(print_r($output , true)); //work with the 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; }

Result-->Error ?> [26-Apr-2019 14:27:11 UTC] [26-Apr-2019 14:27:11 UTC] Leadgen_id-->"369645023759450" [body:protected] => {"error":{"message":"(#803) Some of the aliases you requested do not exist: \"369645023759450\"","type":"OAuthException","code":803,"fbtrace_id":"A++HyKUo4my"}}

----------------------------------------------------------------------------When pass $leadgen_id is static in getLead() function

code-->

<?php require_once 'vendor1/src/Facebook/autoload.php'; $fb = new Facebook\Facebook([ 'app_id' => {app_id}, 'app_secret' => {app_secret}, 'default_graph_version' => 'v2.4', ]); $user_access_token={user_access_token}; try { $response = $fb->get('/me',$user_access_token ); } catch(\Facebook\Exceptions\FacebookResponseException $e) { error_log(print_r($e , true)); } catch(\Facebook\Exceptions\FacebookSDKException $e) { error_log(print_r($e , true)); } $node = $response->getGraphNode(); var_dump($node->getField('id')); $input = json_decode(file_get_contents('php://input'), true); $leadgen_id = json_encode($input['entry'][0]['changes'][0]['value']['leadgen_id']); $form_id = json_encode($input['entry'][0]['changes'][0]['value']['form_id']); $page_id = json_encode($input['entry'][0]['changes'][0]['value']['page_id']);

$lead = getLead(‘369645023759450’,$user_access_token); error_log(print_r($lead , true));

function getLead($leadgen_id,$user_access_token) { //fetch lead info from FB API $graph_url= 'https://graph.facebook.com/v2.3/'.$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); error_log(print_r($output , true)); //work with the 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; }

Result-->lead informations ?> [26-Apr-2019 14:31:34 UTC] "258741369874512" {"created_time":"2019-04-24T14:38:07+0000","id":"369645023759450","field_data":[{"name":"full_name","values":["Rahul Singh"]},{"name":"city","values":["New Delhi"]},{"name":"phone_number","values":["+919910761891"]},{"name":"email","values":["rahulsinghlg\u0040yahoo.com"]}]} [26-Apr-2019 14:31:35 UTC] Array ( [full_name] => Rahul Singh [city] => New Delhi [phone_number] => +919910761891 [email] => rahulsinghlg@yahoo.com )