Facebook Marketing API中的参数Facebook Lead Leadgen表格无效

时间:2017-11-02 05:36:54

标签: php laravel-5.3 facebook-marketing-api

创建Leadgen表单时,我从Facebook Marketing API收到错误。我跟着Facebook指南,但没有任何工作。 API documentation link

之前我成功创建了 leadgen法律内容 leadgen context cards leadgen条件问题组条件问题组csv 即可。之后我尝试创建 Leadgen表单,但API返回 无效参数

    $config = Config::get('facebook');
    $data['account_id'] = 'act_'.$config['ad_account_id'];
    $data['page_id'] = $config['page_id'];

    $api = Api::init($config['app_id'], $config['app_secret'], $config['access_token']);

    // Init facebook
    $legal_params = array(
      'privacy_policy' => array(
        'url' => 'http://example.com/privacy-policy',
        'link_text' => 'Privacy Policy'
      ),
      'custom_disclaimer' => array(
        'title' => 'Terms and Conditions',
        'body' => array(
          'text' => 'My custom disclaimer',
          'url_entities' => array(
            array("offset" => 3, "length" => 6, "url" => 'http://example.com/privacy-policy')
          ),
        ),
        'checkboxes' => array(array(
          "is_required" => false,
          "is_checked_by_default" => false,
          "text" => "Allow to contact you",
          "key" => "checkbox_1",
        ))
      ),
    );

    $legal_res = Api::instance()->call('/'.$data['page_id'].'/leadgen_legal_content',
        RequestInterface::METHOD_POST,
        $legal_params)->getContent();

    $legal_content_id = $legal_res['id'];

    $contex_params = array(
      'title' => 'Thank You',
      'style' => 'LIST_STYLE',
      'content' => array(
        'Easy sign-up flow',
        'Submit your info to have a chance to win',
      ),
      'button_text' => 'Get started',
    );

    $contex_res = Api::instance()->call('/'.$data['page_id'].'/leadgen_context_cards',
        RequestInterface::METHOD_POST,
        $contex_params)->getContent();

    $context_card_id = $contex_res['id'];

    // Conditional Questions
    $conditional_request = Api::instance()->prepareRequest(
      '/'.$data['page_id'].'/leadgen_conditional_questions_group',
      RequestInterface::METHOD_POST);

    $conditional_request->getFileParams()->offsetSet(
      'conditional_questions_group_csv',
      (new FileParameter(public_path().'/facebook/lead-csv-form.csv'))->setMimeType("text/csv"));

    $csv_data = Api::instance()->executeRequest($conditional_request)->getContent();

    $questions_group_id = $csv_data['id'];

    // Create Lead Form
    $form = new LeadgenForm(null, $data['page_id']);
    $form->setData(array(
      LeadgenFormFields::NAME => 'Test LeadAds Form Name',
      LeadgenFormFields::FOLLOW_UP_ACTION_URL => 'https://www.facebook.com/examplepage',
      LeadgenFormFields::QUESTIONS => array(
        (new LeadGenQuestion())->setData(array(
          LeadgenQuestionFields::TYPE => 'EMAIL',
        )),
        (new LeadGenQuestion())->setData(array(
          LeadgenQuestionFields::TYPE => 'CUSTOM',
          LeadgenQuestionFields::LABEL => 'Country',
          'conditional_questions_group_id' => $questions_group_id,
          'dependent_conditional_questions' => array(
            array('name' => 'State'),
            array('name' => 'City'),
          )
        )),
      ),
      'block_display_for_non_targeted_viewer' => true,
      'context_card_id' => $context_card_id,
      'legal_content_id' => $legal_content_id,
    ));
    $form->create();

0 个答案:

没有答案