如何在数据洞察表上按国家/地区对page_fan_city值进行分组

时间:2011-12-20 10:05:36

标签: php facebook facebook-graph-api facebook-insights

首先我的英文不好

通过图表api获取页面统计信息。 (见解/ page_fan_city)

我的查询和Facebook回复如下。

{
   "data": [
      {
         "id": "147197862002528/insights/page_fans_city/lifetime",
         "name": "page_fans_city",
         "period": "lifetime",
         "values": [
            {
               "value": {
                  "istanbul": 20017,
                  "ankara": 9763,
                  "izmir": 7549,
                  "bursa": 3350,
                  "adana": 2949,
                  "antalya": 2687,
                  "konya": 2375,
                  "izmit": 2229,
                  "mersin": 1942,
                  "samsun": 1861,
                  "kayseri": 1444,
                  "maltepe": 1403,
                  "trabzon": 1327,
                  "manisa": 1163,
                  "eskisehir": 1040,
                  "baku": 1015,
                  "denizli": 986,
                  "mugla": 978,
                  "erzurum": 809
               },
               "end_time": "2011-12-17T08:00:00+0000"
            }
         ],
         "description": "Lifetime Aggregated Facebook location data, sorted by city, about the people who like your Page. (Total Count)"
      }
   ],
   "paging": {
      "previous": "https://graph.facebook.com/147197862002528/insights/page_fans_city/lifetime/?access_token=HIDDEN&since=1323682381&until=1323941581",
      "next": "https://graph.facebook.com/147197862002528/insights/page_fans_city/lifetime/?access_token=HIDDEN&since=1324200781&until=1324459981"
   }
}

我得到这些信息。我想得到这个国家的城市。我怎样才能得到国家名称

1 个答案:

答案 0 :(得分:0)

看起来像一个老问题,但只是为了清理你可以将JSON对象分配给一个字符串并通过它递归来获取这些国家:

$response = json_decode($json);

foreach((array)$response->data[0]->values[0]->value as $key => $val) {
        print $key."\n";
}