是否有办法从URL获得facebook的见解数据,并把它放在php变量


Is there way to get facebook insights data from URL and put it in php variables?

我有这样的数据,这是远程URL:

{
   "data": [
      {
         "id": "1234567890",
         "name": "data_name",
         "period": "data_period",
         "values": [
            {
               "value": 52,
               "end_time": "2013-01-21T08:00:00+0000"
            },
            {
               "value": 54,
               "end_time": "2013-01-22T08:00:00+0000"
            },
            {
               "value": 57,
               "end_time": "2013-01-23T08:00:00+0000"
            },
            {
               "value": 58,
               "end_time": "2013-01-24T08:00:00+0000"
            }
      ],
         "title": "Some title",
         "description": "Some description"
      }
   ]
}

是否有办法从链接到php变量?我对php有很好的了解,但我的javascript知识很差,所以我不知道如何实现这一点。从所有这些,我实际上只需要"value"answers"end_time"变量。

这里不需要JavaScript。这是JSON表示法,PHP可以使用标准函数轻松解析它。

试试这个:

$contents = file_get_contents($url); // You can also use cURL here if you like
$obj = json_decode($contents);

则可以将$var视为对象。例如,$obj->data[0]->values将返回一个包含valueend_time字段的对象数组:

Array
(
    [0] => stdClass Object
        (
            [value] => 52
            [end_time] => 2013-01-21T08:00:00+0000
        )
    [1] => stdClass Object
        (
            [value] => 54
            [end_time] => 2013-01-22T08:00:00+0000
        )
    [2] => stdClass Object
        (
            [value] => 57
            [end_time] => 2013-01-23T08:00:00+0000
        )
    [3] => stdClass Object
        (
            [value] => 58
            [end_time] => 2013-01-24T08:00:00+0000
        )
)