简体   繁体   中英

Lead Form Marketing APi Facebook create error

I'm reproducing exactly the same simple example for lead form creation on facebook ( https://developers.facebook.com/docs/marketing-api/guides/lead-ads/create )

I'm using the API SDK PHP and after running $form.create(); i'm recibing this error..

Fatal error: Uncaught FacebookAds\\Http\\Exception\\AuthorizationException: (#100) The parameter questions[0][type] is required in C:\\inetpub\\wwwroot\\leads\\vendor\\facebook\\php-ads-sdk\\src\\FacebookAds\\Http\\Exception\\RequestException.php:

This is the function code.

function create_form($page_id,$form_name,$url_follow,$idlegal,$idcontext){
  $form = new LeadgenForm(null, $page_id);
  $form->setData(array(
  LeadgenFormFields::NAME => $form_name,
  LeadgenFormFields::FOLLOW_UP_ACTION_URL => $url_follow,
  LeadgenFormFields::QUESTIONS => array(
      (new LeadGenQuestion())->setData(array(
         LeadgenQuestionFields::TYPE => 'EMAIL',
         )),
      ),
  'context_card_id' => $idcontext,
  'legal_content_id' => $idlegal,
));
$form->create();
}

$idcontext $idlegal are recently created with succesfully code.

Any Idea? thanks in advance!

I debuged until api:call and dumped this $data (befor call)

Array ( [name] => AGENT-TIME_STAMP-Title [follow_up_action_url] => https://www.site.es/ [questions] => Array ( [0] => FacebookAds\\Object\\LeadGenQuestion Object ( [data:protected] => Array ( [key] => [label] => [options] => [type] => EMAIL ) [_type_checker:protected] => FacebookAds\\TypeChecker Object ( [type_data:FacebookAds\\TypeChecker:private] => Array ( [key] => string [label] => string [options] => list [type] => string ) [enum_data:FacebookAds\\TypeChecker:private] => Array ( ) [primitive_types:FacebookAds\\TypeChecker:private] => Array ( [0] => unsigned int [1] => int [2] => bool [3] => string [4] => Object [5] => datetime [6] => float ) ) ) ) [context_card_id] => 1120914681377165 [legal_content_id] => 1166716330131814 )

Solved thanks to musashii!

LeadgenFormFields::QUESTIONS => array(array('type' => 'EMAIL')),

instead of LeadgenQuestionFields::TYPE => 'EMAIL'

try this 'type' => 'EMAIL'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM