gpt4 book ai didi

php - 如何在 Facebook 广告 API 中访问来自 Facebook 的 protected 属性(property)响应

转载 作者:搜寻专家 更新时间:2023-10-31 21:51:51 28 4
gpt4 key购买 nike

我从对 Facebook 广告的 API 调用中得到一个 protected 对象。

 $page = new Page($page_id);
$leadgen_forms = $page->getLeadgenForms();

我收到这样的回复:

    FacebookAds\Object\Page
(
[response:protected] => FacebookAds\Http\Response Object
(
[response:protected] => Array
(
[data] => Array
(
MY DATA
)
)
)
)

我已经用过Reflection

 $reflect=new \ReflectionClass($leadgen_forms);
$properties=$reflect->getProperties('content');

PtcHandyMan

require_once('PtcHm.php');
PtcHandyMan::register();
$data = PtcHandyMan::getProperty( $leadgen_forms , 'content' );

但我无法访问 protected 属性(property)。有没有办法访问 protected 属性(property)。而且我也不明白为什么 Facebook 会给出 protected 响应。

这是我的全部功能

  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;
}

最佳答案

有很多方法可以访问来自 facebook API 的响应。

您的代码:

$page = new Page($page_id);
$leadgen_forms = $page->getLeadgenForms();

你得到这样的回应:

FacebookAds\Object\Page
(
[response:protected] => FacebookAds\Http\Response Object
(
[response:protected] => Array
(
[data] => Array
(MY DATA)
)
)
)

您可以使用 asArray 方法

$page = new Page($page_id);
$leadgen_forms = $page->getLeadgenForms()->asArray();

https://developers.facebook.com/docs/php/GraphNode/5.0.0

或者如果您不想使用 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
}

关于php - 如何在 Facebook 广告 API 中访问来自 Facebook 的 protected 属性(property)响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40401101/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com