[英]how to access protected property response from facebook in facebook ads api
I am getting a protected object returned from the API call to Facebook Ads. 我从API广告的API调用返回一个受保护的对象。
$page = new Page($page_id);
$leadgen_forms = $page->getLeadgenForms();
I am getting the response like this : 我收到这样的回复:
FacebookAds\Object\Page
(
[response:protected] => FacebookAds\Http\Response Object
(
[response:protected] => Array
(
[data] => Array
(
MY DATA
)
)
)
)
I have already used used Reflection Class 我已经使用过反射类
$reflect=new \ReflectionClass($leadgen_forms);
$properties=$reflect->getProperties('content');
and PtcHandyMan 和PtcHandyMan
require_once('PtcHm.php');
PtcHandyMan::register();
$data = PtcHandyMan::getProperty( $leadgen_forms , 'content' );
but I am not able to access the protected property. 但我无法访问受保护的财产。 Is there any way to access the protected property. 有没有办法访问受保护的财产。 And also I don't get why facebook is giving the protected response. 而且我也不明白为什么facebook会提供受保护的回复。
This is my whole function 这是我的全部功能
function get_page_forms(){
if (!$this->input->is_ajax_request()) {
exit('No direct script access allowed');
}
$page_id = $_POST['page_id'];
$page_access_token = $_POST['page_access_token'];
Api::init('APPID', 'SECRET KEY', $page_access_token);
$page = new Page($page_id);
$leadgen_forms = $page->getLeadgenForms();
//$reflect=new \ReflectionClass($leadgen_forms);
//$properties=$reflect->getProperties('content');
require_once('PtcHm.php');
PtcHandyMan::register();
$data = PtcHandyMan::getProperty( $leadgen_forms , 'content' );
$allFormsArr = $data['data'];
$count = count($allFormsArr);
$output = '<div class="container">
<table class="table table-responsive table-hover">
<thead>
<tr>
<td>Id</td>
<td>Name</td>
<td>Leads csv file</td>
<td>Status</td>
</tr>
</thead>
<tbody>';
for($i=0; $i<$count; $i++){
$output .= '<tr>
<td>'.$allFormsArr[$i]['id'].'</td>
<td>'.$allFormsArr[$i]['name'].'</td>
<td><a href="'.$allFormsArr[$i]['leadgen_export_csv_url'].'" target="_new">Link</a></td>
<td>'.$allFormsArr[$i]['status'].'</td>
</tr>';
}
$output .= '</tbody>
</table>
</div>';
echo $output;
}
Try using getter methods for the property like getContent
. 尝试对getContent
属性使用getter方法。 This might get you access to the protected property. 这可能会让您访问受保护的属性。
There are a lot ways to access the responses from facebook API. 有很多方法可以从facebook API访问响应。
Your code: 你的代码:
$page = new Page($page_id);
$leadgen_forms = $page->getLeadgenForms();
you are getting the response like this : 你得到这样的回应:
FacebookAds\Object\Page
(
[response:protected] => FacebookAds\Http\Response Object
(
[response:protected] => Array
(
[data] => Array
(MY DATA)
)
)
)
You can use asArray method 您可以使用asArray方法
$page = new Page($page_id);
$leadgen_forms = $page->getLeadgenForms()->asArray();
https://developers.facebook.com/docs/php/GraphNode/5.0.0 https://developers.facebook.com/docs/php/GraphNode/5.0.0
or if you don't want to use asArray use simple foreach for deeper levels: 或者如果你不想使用asArray,可以使用简单的foreach来获得更深层次:
foreach ($leadgen_forms as $leadgen_form) {
heres your array. It may be protected so you might want to dig deeper with another foreach and so on
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.