将Facebook json feed添加到MySQL数据库

时间:2012-02-03 23:24:14

标签: mysql facebook api

我想这是一个很大的问题。使用PHP我抓住这个Facebook Graph API json feed json feed link

{
   "data": [
      {
         "id": "10369058551_10150645263758552",
         "from": {
            "name": "Land Rover",
            "category": "Cars",
            "id": "10369058551"
         },
         "message": "This week's Land Rover photo of the week is by Rodrigo Beja. Don't forget to submit your best photos each week to get featured.",
         "link": "http://www.facebook.com/photo.php?fbid=10150645263678552&set=a.443106273551.221975.10369058551&type=1",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif",
         "actions": [
            {
               "name": "Comment",
               "link": "http://www.facebook.com/10369058551/posts/10150645263758552"
            },
            {
               "name": "Like",
               "link": "http://www.facebook.com/10369058551/posts/10150645263758552"
            }
         ],
         "privacy": {
            "description": "United Kingdom",
            "value": "CUSTOM"
         },
         "type": "photo",
         "object_id": "10150645263678552",
         "created_time": "2012-02-03T17:19:03+0000",
         "updated_time": "2012-02-03T22:32:28+0000",
         "likes": {
            "data": [
               {
                  "name": "Mandy Elder",
                  "id": "100000250758731"
               }
            ],
            "count": 85
         },
         "comments": {
            "data": [
               {
                  "id": "10369058551_10150645263758552_6835532",
                  "from": {
                     "name": "John Sharp",
                     "id": "652940638"
                  },
                  "message": "This photo was used as part of the g4 challenge publicity photo pack around 2005-6 \nI remember because at the time I used it as a profile pic on msn \n\nAwesome photo - sums it up perfectly - I love it!!",
                  "created_time": "2012-02-03T21:39:48+0000"
               },
               {
                  "id": "10369058551_10150645263758552_6835852",
                  "from": {
                     "name": "Kathryn Piddington",
                     "id": "777370532"
                  },
                  "message": "Mud is good for the soul :)",
                  "created_time": "2012-02-03T22:32:28+0000"
               }
            ],
            "count": 14
         }
      },
      {
         "id": "10369058551_355476307803889",
         "from": {
            "name": "Land Rover",
            "category": "Cars",
            "id": "10369058551"
         },
         "message": "Click below to watch the new Range Rover Sport advert and catch up on the latest Land Rover and Range Rover news in this week\u2019s round-up. ",
         "picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQAx7xz602rfhyIn&w=90&h=90&url=http\u00253A\u00252F\u00252Fblog.landrover.com\u00252Fwp-content\u00252Fuploads\u00252F12my_rrs_044_LowRes.jpg",
         "link": "http://blog.landrover.com/vehicles/the-land-rover-and-range-rover-weekly-19-3578.html#axzz1lKthI4F1",
         "name": "The Land Rover and Range Rover Weekly 19 | Land Rover Blog",
         "caption": "blog.landrover.com",
         "description": "In this week\u2019s round-up of all things Land Rover and Range Rover, the new Range Rover Sport advert, Which? figures reveal  the running costs of the Range Rover Evoque in comparison with competitors and a history of Land Rover narrated by Ranulph Fiennes.",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yD/r/aS8ecmYRys0.gif",
         "actions": [
            {
               "name": "Comment",
               "link": "http://www.facebook.com/10369058551/posts/355476307803889"
            },
            {
               "name": "Like",
               "link": "http://www.facebook.com/10369058551/posts/355476307803889"
            }
         ],
         "privacy": {
            "description": "United Kingdom",
            "value": "CUSTOM"
         },
         "type": "link",
         "created_time": "2012-02-03T16:44:42+0000",
         "updated_time": "2012-02-03T16:44:42+0000",
         "likes": {
            "data": [
               {
                  "name": "Steve Nesbitt",
                  "id": "533982936"
               }
            ],
            "count": 10
         },
         "comments": {
            "count": 0
         }
      },
      {
         "id": "10369058551_10150642499593552",

我想将顶级项目放到mysql表中,然后将每个子级别放到另一个表中,保持每个表之间的键/链接,然后是子级别的任何子级别,并将其链接起来。这可能吗?

我已经达到了这个目标: -

    $page = file_get_contents($url);
    $json_output = json_decode($page, true);

我无法弄清楚如何通过每行掠夺并将数据添加到Mysql表中。

感谢您的提前帮助

乔纳森

1 个答案:

答案 0 :(得分:0)

尝试将其作为数组循环,然后进行sql查询。每个数组都放置一个唯一键(用于顶级项)。因此,您可以使用顶级键来创建子级外键..