public function setup()
 {
     parent::setup();
     $page = new Page($this->getConfig()->pageId);
     $forms = $page->getLeadgenForms();
     if ($forms->count() === 0) {
         $this->markTestSkipped(sprintf('LeadgenForms can\'t be created through the API.' . ' Page %s has no leadgen forms', (string) $this->getConfig()->pageId));
     }
     $this->leadgenFormId = $forms->current()->{LeadgenFormFields::ID};
 }
 public function setup()
 {
     parent::setup();
     $limit = 25;
     $page = new Page($this->getConfig()->pageId);
     $forms = $page->getLeadgenForms(array(LeadgenFormFields::ID), array('limit' => $limit));
     $forms->setUseImplicitFetch(false);
     // Force-disable pagination
     /** @var LeadgenForm $form */
     foreach ($forms as $form) {
         $leads = $form->getLeads();
         if ($leads->count() > 0) {
             $this->leadId = $leads->current()->{LeadFields::ID};
             break;
         }
     }
     if ($this->leadId === null) {
         $this->markTestSkipped(sprintf('Leads can\'t be created through the API.' . ' The first %d leadgen forms of Page %s have no leads', $limit, (string) $this->getConfig()->pageId));
     }
 }
Exemple #3
0
 /**
  * @param array $fields
  * @param array $params
  * @return Cursor
  */
 public function getPages(array $fields = array(), array $params = array())
 {
     return $this->getManyByConnection(Page::className(), $fields, $params);
 }
use FacebookAds\Object\AdUser;
use FacebookAds\Object\Page;
function processFieldData(&$pg_lead, $data)
{
    foreach ($data as $data_set) {
        $pg_lead[$data_set['name']] = pg_escape_string($data_set['values'][0]);
    }
    if (isset($pg_lead['full_name'])) {
        $names = explode(' ', $pg_lead['full_name']);
        $pg_lead['first_name'] = array_shift($names);
        $pg_lead['last_name'] = implode(' ', $names);
    }
}
session_start();
$cwd = getcwd();
$conf = json_decode(file_get_contents("{$cwd}/conf/conf.json"), true);
$pg = pg_connect($conf['pg_connect']);
$access_token = isset($_SESSION['facebook_access_token']) ? $_SESSION['facebook_access_token'] : $conf['access_token'];
Api::init($conf['app_id'], $conf['app_secret'], $_SESSION['facebook_access_token']);
$page = new Page($conf['page_id']);
$leadgen_forms = $page->getLeadgenForms();
echo '<pre>';
foreach ($leadgen_forms as $value) {
    $form_leads = $value->getLeads();
    foreach ($form_leads as $lead) {
        $pg_lead = array('id' => pg_escape_string($lead->id), 'created_time' => pg_escape_string($lead->created_time));
        processFieldData($pg_lead, $lead->field_data);
        echo json_encode($pg_lead) . "\n";
    }
}
echo '</pre>';