标准化图表或 fql.query 的结果

发布于 2024-12-22 07:55:15 字数 3689 浏览 2 评论 0原文

我正在运行一个应用程序,该应用程序调用图表和 fql.query 来获取见解信息。 (它碰巧模拟了数十个应用程序并提取统计数据)查询时我得到了几种不同的格式,我想知道是否有更好的方法来“标准化”结果?

如果 SDK 中有这样的东西就好了,因为 Facebook 格式/数据一直在变化。我在哪里提出 SDK 请求?

获取键值的代码--- [code]

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

[/code]

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

I'm running an application that calls both the graph and fql.query for Insights information. (It happens to impersonate dozens of apps and pulls stats) I get a couple different formats back when querying and I'm wondering if there's a better way to 'normalize' results?

It would be nice to have something like this in the SDK, since Facebook formats/ data changes all the time. Where do I make an SDK request?

Code to get key-value---
[code]

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

[/code]

Results from 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
                )

        )

Results from graph --

 => 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三月梨花 2024-12-29 07:55:15

根据我的经验,从 FQL 表返回的“对象属性”与新图形 API 对象的“对象属性”之间不存在 1:1 的相关性。 FQL 表上的属性比我所看到的图表中的属性多得多。试图把它们绑在一起就像给猫洗澡一样。可以做,但是会很痛苦!!

我的建议是根据项目需求确定您想要实现的目标,然后确定 FQL 还是 Graph API 是否是满足每个需求的最佳途径。使用图表可能更容易完成一项要求,而使用 FQL 可能更容易完成另一项要求。祝你好运。

From my experience there's no 1:1 correlation between "object properties" being returned from the FQL tables to that of the new graph API objects. There's so many more properties on the FQL tables than there are in the graph from what I've seen. Trying to get them tied together would be like giving a cat a bath. It can be done, but it's going to be painful!!

My suggestions would be to determine from the project requirements what you're trying to accomplish and then determine whether FQL or Graph API is your best route to getting to each requirement. One requirement might be easier done with the graph, and another using FQL. Good luck.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文