Lead Form Marketing APi Facebook create error - php

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'

Related

Use PHP to create list of WHM accounts

I would like to know if it is possible to connect to my WHM with PHP using the cPanel PublicAPI PHP Repository https://github.com/CpanelInc/publicapi-php so that I can create a list of the accounts in the WHM.
Is there anything I should know? Are there any restrictions? I simply want to populate a list of my accounts that are in my WHM.
Right now I'm getting an error
Warning: count(): Parameter must be an array or an object that implements Countable in
I was wondering if there was something blocking me?
Here is what my code looks like, I'd like to create a php variable to holds the array data, then loop through it printing the account domain name
require_once '../_libraries/publicapi-php-master/Cpanel/Util/Autoload.php';
$config = array(
'service' => array(
'whm' => array(
'config' => array(
'host' => 'XXXXXXXXXXXXXX',
'user' => 'XXXXXXXXXXXXXX',
'password' => 'XXXXXXXXXX'
),
),
),
);
$cp = Cpanel_PublicAPI::getInstance($config);
$accounts = $cp->whm_api('listaccts');
print_R($accounts);
#print $accounts->_response->dataContainer->storage->acct->dataContainer->storage[0];
When I do a print_r($accounts) this is what I get, I just need to know how to traverse this and loop through it with PHP. I can see in this output the first domain is cfpacking.com, that is the data I'm after.
Cpanel_Query_Object Object
(
[_query:Cpanel_Query_Object:private] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[adapter] => whostmgr
[client] => curl
[url] => https://XXXXXXXXXXXXXX:2087/json-api/listaccts
[args] =>
[argsArray] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
)
[authstr] => Authorization: Basic XXXXXXXXXXXXXXXXXXXXXXX==
[directURL] =>
)
)
)
[_response:Cpanel_Query_Object:private] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[status] => 1
[statusmsg] => Ok
[acct] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[0] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
[inodeslimit] => 500000
[ip] => XXXXXXXXXXXXXXX
[mailbox_format] => maildir
[plan] => default
[maxftp] => unlimited
[maxparked] => unlimited
[owner] => XXXXXXXXXXXXXXXXXXX
[maxpop] => unlimited
[email] => XXXXXXXXXXXXXXXXXXXXXX
[max_email_per_hour] => 500
[disklimit] => unlimited
[maxlst] => unlimited
[min_defer_fail_to_trigger_protection] => 5
[backup] => 1
[startdate] => 17 Dec 27 15:59
[inodesused] => 3281
[maxsql] => unlimited
[max_defer_fail_percentage] => 25
[ipv6] => Cpanel_Core_Object Object
(
[dataContainer:protected] => ArrayObject Object
(
[storage:ArrayObject:private] => Array
(
)
)
)
[max_emailacct_quota] => unlimited
[maxsub] => unlimited
[unix_startdate] => 1514411971
[outgoing_mail_hold] => 0
[partition] => home
[legacy_backup] => 1
[maxaddons] => unlimited
[suspendtime] => 0
[uid] => 1750
[suspendreason] => not suspended
[suspended] => 0
[user] => XXXXXXXXXXXXXX
[domain] => cfpacking.com
[diskused] => 79M
[theme] => paper_lantern
[temporary] => 0
[is_locked] => 0
[shell] => /bin/bash
[outgoing_mail_suspended] => 0
)
)
)
[1] => Cpanel_Core_Object Object
The response object can be turned into an array using the following syntax:
require_once '../_libraries/publicapi-php-master/Cpanel/Util/Autoload.php';
$config = array(
'service' => array(
'whm' => array(
'config' => array(
'host' => 'XXXXXXXXXXXXXXXXXXXX',
'user' => 'XXXXXXXXXXXXXXXXXXXX',
'password' => 'XXXXXXXXXXXXXXXX'
),
),
),
);
$cp = Cpanel_PublicAPI::getInstance($config);
$accounts = $cp->whm_api('listaccts',array('search'=>'XXXXXXXXX','searchtype'=>'owner'));
$accounts = $accounts->getResponse('array')['acct'];
foreach($accounts as $account){
print $account['domain'];
print '<br />';
}
The library(https://github.com/CpanelInc/publicapi-php) contains code that generates warnings in php 7.2 because of a breaking change. Because the library hasn't been maintaned for 9 years you will have to fix it yourself.
The fix:
old:
Cpanel/PublicApi.php line 343
if (count($storedServicesConfig) > 1) {
new:
Cpanel/PublicApi.php line 343
if (count($storedServicesConfig->getAllData()) > 1) {

How to get value from the given object response from Twinfield in Laravel/Lumen?

This is the response when I call the login method from twinfield API. It given the session id and cluster namespace, but the problem is how to get the value from it.
$customerApiConnector = new \PhpTwinfield\ApiConnectors\CustomerApiConnector($login);
print_r($customerApiConnector);die;
Output:
PhpTwinfield\ApiConnectors\CustomerApiConnector Object
(
[service:protected] => PhpTwinfield\Services\ProcessXmlService Object
(
[trace] => 1
[compression] => 32
[_stream_context] => Resource id #153
[_soap_version] => 1
[sdl] => Resource id #154
[__default_headers] => Array
(
[0] => SoapHeader Object
(
[namespace] => http://www.twinfield.com/
[name] => Header
[data] => Array
(
[SessionID] => f7b4c213-1a01-4c7c-87cb-7de80b1583fe
)
[mustUnderstand] =>
)
)
)
)
This is the other object.
Array
(
[1] => PhpTwinfield\CustomerAddress Object
(
[ID:PhpTwinfield\CustomerAddress:private] => 1
[type:PhpTwinfield\CustomerAddress:private] => invoice
[default:PhpTwinfield\CustomerAddress:private] => true
[name:PhpTwinfield\CustomerAddress:private] => Anand
[contact:PhpTwinfield\CustomerAddress:private] =>
[country:PhpTwinfield\CustomerAddress:private] => IN
[city:PhpTwinfield\CustomerAddress:private] => Indore
[postcode:PhpTwinfield\CustomerAddress:private] => 452001
[telephone:PhpTwinfield\CustomerAddress:private] =>
[fax:PhpTwinfield\CustomerAddress:private] =>
[email:PhpTwinfield\CustomerAddress:private] => anand#comfisoft.com
[field1:PhpTwinfield\CustomerAddress:private] =>
[field2:PhpTwinfield\CustomerAddress:private] => lig
[field4:PhpTwinfield\CustomerAddress:private] =>
[field5:PhpTwinfield\CustomerAddress:private] =>
[field6:PhpTwinfield\CustomerAddress:private] =>
)
)
Try this it will work ;)
function accessProtectedProperty($obj, $prop)
{
$reflection = new \ReflectionClass($obj);
$property = $reflection->getProperty($prop);
$property->setAccessible(true);
return json_decode($property->getValue($obj));
}

How to write Laravel Query in two parts

I am working with Laravel 5.2. I want to write a query in two parts like this:
$getData = DB::table($table)
->where($where);
$getData->first();
return $getData;
But it is not working for me. It Not provides correct data to me.
It gives:
Array ( [aggregate] => [columns] => [distinct] => [from] => countries [joins] => [wheres] => Array ( [0] => Array ( [type] => Nested [query] => Array ( [aggregate] => [columns] => [distinct] => [from] => countries [joins] => [wheres] => Array ( [0] => Array ( [type] => Basic [column] => country_name [operator] => = [value] => India [boolean] => and ) ) [groups] => [havings] => [orders] => [limit] => [offset] => [unions] => [unionLimit] => [unionOffset] => [unionOrders] => [lock] => ) [boolean] => and ) ) [groups] => [havings] => [orders] => [limit] => 1 [offset] => [unions] => [unionLimit] => [unionOffset] => [unionOrders] => [lock] => )
But it works correctly when i call like this:
$getData = DB::table($table)
->where($where)->first();
return $getData;
Can we not call a query in two parts in laravel.
You have to get back the returned data from $getData->first();
$getData = DB::table($table)
->where($where);
$getData = $getData->first(); // <----
return $getData;

Extracting data from this object/array? How to do it

Here is a snippet of the print off of $wp_scripts
WP_Scripts Object
(
[base_url] => http://*****
[content_url] => http://*****
[default_version] => 3.5.1
[in_footer] => Array
(
)
[concat] =>
[concat_version] =>
[do_concat] =>
[print_html] =>
[print_code] =>
[ext_handles] =>
[ext_version] =>
[default_dirs] => Array
(
[0] => /wp-admin/js/
[1] => /wp-includes/js/
)
[registered] => Array
(
[utils] => _WP_Dependency Object
(
[handle] => utils
[src] => /wp-includes/js/utils.min.js
[deps] => Array
(
)
How would i Extract some data, for example "/wp-includes/js/utils.min.js"??
Thanks
$wp_scripts->registered['utils']->src
Accessing object properties via ->
Accessing array elements via [/* String or integer here*/]
$object = new WP_Scripts;
$src = $object->registered['utils']->src;

Fetching mysql records from CakePHP with specific index

I am using the following cakephp query to retrieve data from mysql:
$tops = $this->PageBanner->find('all', array(
'conditions' => array(
'PageBanner.status' => 1
),
'fields' => array(
'PageBanner.page_url',
'PageBanner.image',
'PageBanner.logo',
'PageBanner.logo_text',
'PageBanner.content'
)
));
This query returns me the following results:
[0] => Array
(
[PageBanner] => Array
(
[page_url] => index
[image] => home_banner.png
[logo] => home_logo.png
[logo_text] => abc
[content] => abc.
)
)
[1] => Array
(
[PageBanner] => Array
(
[page_url] => write_review
[image] => kids2.png
[logo] => home_logo.png
[logo_text] => abc
[content] => abc.
)
)
But I want the data to be returned in the following format:
[index] => Array
(
[page_url] => index
[image] => home_banner.png
[logo] => home_logo.png
[logo_text] => abc
[content] => abc.
)
[write_review] => Array
(
[page_url] => write_review
[image] => kids2.png
[logo] => home_logo.png
[logo_text] => abc
[content] => abc.
)
I need page_url field content in place of Array index (e.i. 0, 1). Is that possible to get data in this format or I need to manually configure the arrays?
$result = Set::combine($tops, '{n}.PageBanner.page_url', '{n}.PageBanner');
pr($result);

Categories