Closed 8lall0 closed 5 years ago
Don't know if you ever came right, but I found a solution for anybody also struggling with this.
$ThisLead = (new Lead($id))->getSelf($fields,$params)->exportAllData();
I am currently struggling to encode the above to proper json, but the following might also help someone:
$LeadCreatedTime = $ThisLead['created_time'];
$LeadID = $ThisLead['id'];
foreach ($ThisLead['field_data'] as $key => $value) {
print_r($value['name']);
print_r(': ');
print_r($value['values'][0]);
print_r('<br>');
}
Just do a var_dump on the $ThisLead to see all info. Cannot confirm if this is the correct way of using it, but there is no other solution I could find.
Just an update on the above, I realized that piece of code was quite intensive in terms of API calls and rate limiting etc. Below is my working example to get lead data for anyone who is struggling
//$datefrom used to filter leads where date is greater than X
if(isset($_GET['datefrom']) && !empty($_GET['datefrom'])){
$datefrom = $_GET['datefrom'];
} else {
$datefrom = "";
}
$ad = new LeadgenForm('1234567890123456');
if (!empty($datefrom))
{
$leads = $ad->getLeads(array(), array(
AdReportRunFields::FILTERING => array(
array(
'field' => 'time_created',
'operator' => 'GREATER_THAN',
'value' => $datefrom,
),
),
));
}
else
{
$leads = $ad->getLeads();
}
foreach ($leads as $these => $those)
{
//See php-business-sdk/src/FacebookAds/Object/Fields/LeadFields.php for available fields
$LeadFieldsID = $those->{LeadFields::ID};
$LeadCreatedTime = $those->{LeadFields::CREATED_TIME};
print_r('_______________________________________');
print_r('<br>');
print_r("Lead ID: ");
print_r($LeadFieldsID);
print_r('<br>');
print_r("Date Created: ");
print_r($LeadCreatedTime);
print_r('<br>');
$LeadFieldsData = $those->{LeadFields::FIELD_DATA};
foreach ($LeadFieldsData as $key => $value)
{
print_r('<br>');
print_r($value['name']);
print_r(': ');
print_r($value['values'][0]);
print_r('<br>');
}
}
This will be fix in next release
Using the example for leadgen:
it outputs:
Call to undefined method FacebookAds\Object\Lead::getContent()