我正在运行一个调用图表和fql.query的应用程序来获取Insights信息。 (它恰好冒充了几十个应用程序并提取统计数据)在查询时我得到了几种不同的格式,我想知道是否有更好的方法来“正常化”结果?
在SDK中有这样的东西会很好,因为Facebook格式/数据一直在变化。我在哪里提出SDK请求?
获取键值的代码--- [代码]
public function saveResults($application = null, $result = array())
{
// graph insights are under a data key
if(isset($result['data'])) {
$this->saveResults($application, $result['data']);
}
// graph insights are under a values array
elseif(isset($result['values'])) {
foreach($result['values'] as $k => $v) {
$this->saveResult($application, $result['name'], $v['value'], $result['period'], $v['end_time']);
}
}
// fql.query results have a metric and value
elseif(isset($result['metric'])) {
$this->saveResult($application, $result['metric'], $result['value'], $result['period'], $result['end_time']);
}
// otherwise save key values
elseif(is_array($result)) {
foreach($result as $key => $val) {
if(is_numeric($key) && is_array($val)) {
$this->saveResults($application, $val);
}
else {
$this->saveResult($application, $key, $val);
}
}
}
}
[/代码]
fql -
的结果=> Array
(
[0] => Array
(
[app_id] => 1248...
[api_key] => 1248...
[canvas_name] => ABC123
[display_name] => ABC123
[company_name] =>
[developers] => Array
(
)
[restriction_info] => Array
(
)
[daily_active_users] => 0
[weekly_active_users] => 0
[monthly_active_users] => 8
)
)
=> Array
(
[0] => Array
(
[metric] => application_canvas_views
[value] => 0
[period] => 86400
[end_time] => 1317538800
)
)
图表的结果 -
=> Array
(
[id] => 1248...
[name] => ABC123
[picture] => https://fbcdn-profile...
[link] => http://www.facebook.com/ABC123
[likes] => 58450
[category] => Product/service
[website] => http://www.ABC123..
=> Array
(
[data] => Array
(
[0] => Array
(
[id] => ABC123.../insights/page_like_adds/day
[name] => page_like_adds
[period] => day
[values] => Array
(
[0] => Array
(
[value] => 60
[end_time] => 2011-01-01T08:00:00+0000
)
[1] => Array
(
[value] => 15
[end_time] => 2011-01-02T08:00:00+0000
)
[2] => Array
(
[value] => 2
答案 0 :(得分:0)
根据我的经验,从FQL表返回的“对象属性”与新图API对象的对象属性之间没有1:1的相关性。 FQL表中的属性比我在图中看到的要多得多。试图让他们绑在一起就像给猫洗澡一样。它可以做到,但它会很痛苦!
我的建议是根据项目要求确定您要完成的工作,然后确定FQL或Graph API是否是达到每项要求的最佳途径。使用图表可以更轻松地完成一个要求,使用FQL可以更轻松地完成祝你好运。