如何使用FQL多天获取`page_fan_adds`

时间:2012-07-31 18:43:51

标签: facebook facebook-graph-api facebook-fql

我可以使用FQL获取特定日期page_fan_adds的值。

SELECT metric, value FROM insights WHERE object_id = XXX AND 
metric = "page_fan_adds" AND end_time = end_time_date("2012-07-20") AND 
period = period("day")

我得到了:

{"data": [
    {"metric": "page_fan_adds", 
      "value": 1}
]}

但是,使用Graph API,我可以获得一个月的数据:graph.facebook.com/XXX/insights/page_fan_adds/?since= 1340175600&until=1342767600。我得到了:

{"data": [
  {"id": "XXX/insights/page_fan_adds/day", 
   "name": "page_fan_adds", 
   "period": "day", 
   "values": [
     {"value": 4, 
      "end_time": "2012-06-21T07:00:00+0000"}, 
     {"value": 2, 
      "end_time": "2012-07-20T07:00:00+0000"}
  ], 
  "title": "Daily New Likes", 
  "description": "Daily The number of new people who have liked your Page (Total Count)"}], 
"paging": {
  "previous": "https://graph.facebook.com/XXX/insights/page_fan_adds/?since=1337583600&until=%201340175600", 
  "next": "https://graph.facebook.com/XXX/insights/page_fan_adds/?since=1342767600&until=1345359600"
  }
}
对于period

day列只能是page_fan_adds。那么如何使用FQL获取一个月的数据?

2 个答案:

答案 0 :(得分:1)

看起来这是通过分别查询所有日期然后聚合它们来实现此目的的唯一方法。

SELECT metric, value FROM insights WHERE object_id=XXX AND 
   metric = "page_fan_adds" AND period = period("day") AND (
      end_time = end_time_date("2012-07-20") OR 
      end_time = end_time_date("2012-07-19") OR
      ...
      end_time = end_time_date("2012-06-21")
   )

尝试end_time IN会抛出错误。

答案 1 :(得分:0)

SELECT metric, value FROM insights 
WHERE object_id=XXX 
AND metric = "page_fan_adds" 
AND period = period("day") 
AND end_time in ( 
  end_time_date("2012-07-20"), 
  end_time_date("2012-07-19"), 
  end_time_date("2012-06-21")
)