2012-02-03 29 views
0

我想这是一个很大的问题。使用PHP我抓住这个Facebook的图形API JSON提要json feed link将Facebook json feed添加到MySQL db

{ 
    "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表,然后每个子级anaother表保持每个表,然后任意之间的键/链接子级别的子级别并将其链接。这可能吗?

我已经尽量了,因为这: -

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

我无法弄清楚如何掠夺hrough每一行和德数据添加到MySQL表。

感谢您的帮助提前

乔纳森

+1

我会小心你的应用程序在数据库中存储的信息作为Facebook政策(http://developers.facebook.com/policy/ )相当严格。 – DMCS 2012-02-03 23:52:19

回答

0

尝试循环作为数组然后进行SQL查询。每个数组放置一个唯一的键(用于顶级项目)。所以,你可以使用你的顶级密钥来分级别的外键..

+0

你能举个例子吗?我有这个迄今为止,这适用于顶级数组,但不适用于子级数组foreach($ json_output ['data'] as $ key => $ val){ $ dadded = date(“Ymd H:i: s“,time()); \t // echo $ val ['id']。“
”; \t $ pageid ='118719108161146'; \t $ pid = mysql_real_escape_string($ val ['id']); – 2012-02-04 10:56:45