Alex Mathew
Alex Mathew

Reputation: 1554

Facebook API and Json with PHP,how to?

https://graph.facebook.com/search?q=India&type=post i am using the above api of Facebook and i am getting following Output

{
   "data": [
      {
         "id": "501585456_163489377008878",
         "from": {
            "name": "Ian Robinson",
            "id": "501585456"
         },
         "message": "\"Media subdues the public\".  Noam Chomsky still firing http://www.outlookindia.com/article.aspx?267553",
         "picture": "http://external.ak.fbcdn.net/safe_image.php?d=c6a004d1d5a2ba4cb419ae93c26b2b1f&w=90&h=90&url=http%3A%2F%2Fphoto.outlookindia.com%2Fimages%2Fgallery%2F20101020%2Fnoam_chomsky_20101101.jpg",
         "link": "http://outlookindia.com/article.aspx?267553",
         "name": "www.outlookindia.com | \u201cMedia Subdues The Public. It\u2019s So In India, Certainly\u201d",
         "caption": "outlookindia.com",
         "description": "Noam Chomsky has a veritable cult following among those who are sceptical about views the liberal media espouses and government propaganda machinery spawns to suit their often overlapping agendas. Compelling is his criticism, breathtaking is his knowledge, persuasive is his voice, and deep runs his ",
         "icon": "http://static.ak.fbcdn.net/rsrc.php/zD/r/aS8ecmYRys0.gif",
         "type": "link",
         "created_time": "2010-10-24T13:44:01+0000",
         "updated_time": "2010-10-24T13:44:01+0000"
      },

How can we convert it into php and get following output

Name:Ian Robinson
Description:

Upvotes: 0

Views: 2912

Answers (1)

Sarfraz
Sarfraz

Reputation: 382666

Update

$array = json_decode($your_json_data, true);
echo $array['data']['id'];
echo $array['data']['message'];
echo $array['data']['description'];
// and so on

You can use the json_decode() function and treat it like normal array.

json_decode — Decodes a JSON string

Example:

 var_dump(json_decode($json, true));

Upvotes: 3

Related Questions