1

我这里有一个 Json 字符串。https://graph.facebook.com/402341223174008_403132789761518?access_token=AAACEdEose0cBAKvST4yvRNg0ViRuvwLdKlCSk13x2NWAobGfq0QOASS3yBdsm1e4aZA57ZAfCjSCD0ta2HWjo3ZClgoYlR6CPFFdu877D _ 现在这包含来自 facebook 群组帖子的评论。我想得到所有评论这篇文章的人的名字。

我想要所有名字,并且不应该重复任何名字(因为很多人不止一次评论过)。

我们可以通过

$a = file_get_contents ('https://graph.facebook.com/402341223174008_403132789761518?access_token=AAACEdEose0cBAKvST4yvRNg0ViRuvwLdKlCSk13x2NWAobGfq0QOASS3yBdsm1e4aZA57ZAfCjSCD0ta2HWjo3ZClgoYlR6CFFdu4q7180h8D1P7A87');
$json_decoded = json_decode($a);
echo $json_decoded->comments->data[1]->from->name;

下面是完整的 JSON 字符串。请帮我。

{
   "id": "402341223174008_403132789761518",
   "from": {
      "name": "\u015e\u0117xy Gi\u0159l",
      "id": "100004829461101"
   },
   "to": {
      "data": [
         {
            "version": 1,
            "name": "Magic box 30k+ With Safe Magicians [ Save App. Sharing ]",
            "id": "402341223174008"
         }
      ]
   },
   "message": "give me linkssssssssssssssssssssss\n\nsubs k liye 20k + must",
   "actions": [
      {
         "name": "Comment",
         "link": "http://www.facebook.com/402341223174008/posts/403132789761518"
      },
      {
         "name": "Like",
         "link": "http://www.facebook.com/402341223174008/posts/403132789761518"
      }
   ],
   "privacy": {
      "value": ""
   },
   "type": "status",
   "created_time": "2012-12-14T15:54:30+0000",
   "updated_time": "2012-12-14T17:38:33+0000",
   "likes": {
      "data": [
         {
            "name": "Jaideep Singh",
            "id": "100002474286855"
         }
      ],
      "count": 1
   },
   "comments": {
      "data": [
         {
            "id": "402341223174008_403132789761518_403133536428110",
            "from": {
               "name": "Gurkaran Singh",
               "id": "100001523330551"
            },
            "message": "https://m.facebook.com/profile.php?id=234028326728478&refid=5\n\nhttps://m.facebook.com/channeVTBP?refid=5\n\nDone ispe krunga \n\nhttps://m.facebook.com/channeVTBP?refid=5",
            "created_time": "2012-12-14T15:57:07+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403133656428098",
            "from": {
               "name": "Nikhil Nikki Varshney",
               "id": "100002729097951"
            },
            "message": "http://m.facebook.com/profile.php?id=514287051931593&refid=5&ref=stream",
            "created_time": "2012-12-14T15:57:48+0000",
            "likes": 2
         },
         {
            "id": "402341223174008_403132789761518_403133766428087",
            "from": {
               "name": "S\u0177\u00ea\u010f S\u0103\u00e5d S\u0127a\u0127",
               "id": "100001550089518"
            },
            "message": "1.\nhttps://www.facebook.com/SaadKaFanPage\n2.\nhttps://www.facebook.com/pages/Mine-Worst-Enemy-Is-Mine-Heart-Its-Of-Mine-But-Beats-For-U/370095696418243\n\nSUBS:\nhttps://www.facebook.com/stub.sm0ker",
            "created_time": "2012-12-14T15:58:20+0000",
            "likes": 3
         },
         {
            "id": "402341223174008_403132789761518_403133856428078",
            "from": {
               "name": "Shandy Orbanto Duplesis",
               "id": "631693473"
            },
            "message": "http://www.facebook.com/whydoihurttheoneilove",
            "created_time": "2012-12-14T15:58:43+0000",
            "likes": 2
         },
         {
            "id": "402341223174008_403132789761518_403133869761410",
            "from": {
               "name": "Nikhil Nikki Varshney",
               "id": "100002729097951"
            },
            "message": "http://m.facebook.com/profile.php?id=356320534384116&refid=5&ref=stream Done page",
            "created_time": "2012-12-14T15:58:47+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403134183094712",
            "from": {
               "name": "Amar Jhutty",
               "id": "100001142236515"
            },
            "message": "https://www.facebook.com/amar.simran1",
            "created_time": "2012-12-14T16:00:01+0000",
            "likes": 2
         },
         {
            "id": "402341223174008_403132789761518_403135436427920",
            "from": {
               "name": "Mandeep Kumar",
               "id": "100001396765502"
            },
            "message": "cc",
            "created_time": "2012-12-14T16:03:50+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403135636427900",
            "from": {
               "name": "\u011c\u1ec3m\u012f\u00f1\u00ee G\u016f\u0155\u0142",
               "id": "1311267291"
            },
            "message": "\u003C3",
            "created_time": "2012-12-14T16:04:20+0000"
         },
         {
            "id": "402341223174008_403132789761518_403136286427835",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "ban ja Mandeep Kumar",
            "message_tags": [
               {
                  "id": "100001396765502",
                  "name": "Mandeep Kumar",
                  "type": "user",
                  "offset": 7,
                  "length": 13
               }
            ],
            "created_time": "2012-12-14T16:06:33+0000"
         },
         {
            "id": "402341223174008_403132789761518_403136353094495",
            "from": {
               "name": "Romeo Boy Romy",
               "id": "100001621695238"
            },
            "message": "Page Links\n\nhttp://www.facebook.com/pages/Distance-Doesnt-Matter-I-Love-U/419648838104003?ref=hl\n\nhttp://www.facebook.com/pages/Teens-J\u0025CF\u002585st-Wanna-Have-Fun/306235916151862?ref=hl\n\nhttp://www.facebook.com/pages/L-a-F-u-N-d-E-r-s/291145307562223\n\nSub button\n\nhttp://www.facebook.com/rape.addiicted",
            "created_time": "2012-12-14T16:06:55+0000",
            "likes": 3
         },
         {
            "id": "402341223174008_403132789761518_403136406427823",
            "from": {
               "name": "Mandeep Kumar",
               "id": "100001396765502"
            },
            "message": "w8 net b bc kar raha hai",
            "created_time": "2012-12-14T16:07:13+0000"
         },
         {
            "id": "402341223174008_403132789761518_403136419761155",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "added h :D",
            "created_time": "2012-12-14T16:07:21+0000"
         },
         {
            "id": "402341223174008_403132789761518_403136626427801",
            "from": {
               "name": "Gurkaran Singh",
               "id": "100001523330551"
            },
            "message": "mera link add kiyA...???",
            "created_time": "2012-12-14T16:07:59+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403136909761106",
            "from": {
               "name": "S\u0177\u00ea\u010f S\u0103\u00e5d S\u0127a\u0127",
               "id": "100001550089518"
            },
            "message": "mera add Kardiaaa ? :P",
            "created_time": "2012-12-14T16:08:54+0000",
            "likes": 2
         },
         {
            "id": "402341223174008_403132789761518_403137253094405",
            "from": {
               "name": "Ranvijay Singh",
               "id": "100001606084450"
            },
            "message": "\u015e\u0117xy Gi\u0159l aur bhi koi code collect kar raha hai kya?",
            "message_tags": [
               {
                  "id": "100004829461101",
                  "name": "\u015e\u0117xy Gi\u0159l",
                  "type": "user",
                  "offset": 0,
                  "length": 9
               }
            ],
            "created_time": "2012-12-14T16:10:07+0000"
         },
         {
            "id": "402341223174008_403132789761518_403137276427736",
            "from": {
               "name": "Gurkaran Singh",
               "id": "100001523330551"
            },
            "message": "Mera ek aur hai isse bhi krr dena add \nhttps://m.facebook.com/profile.php?id=196541297108554&refid=12\n\nGet mai 4.3k page pe krunga pichle cmmnt me uska link hai",
            "created_time": "2012-12-14T16:10:15+0000"
         },
         {
            "id": "402341223174008_403132789761518_403137373094393",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "all added jis like h wo sub added or jitne pe diye utne pe done h",
            "created_time": "2012-12-14T16:10:43+0000"
         },
         {
            "id": "402341223174008_403132789761518_403137476427716",
            "from": {
               "name": "S\u0177\u00ea\u010f S\u0103\u00e5d S\u0127a\u0127",
               "id": "100001550089518"
            },
            "message": "\u015e\u0117xy Gi\u0159l mera sub add hona chahiye bas :D",
            "message_tags": [
               {
                  "id": "100004829461101",
                  "name": "\u015e\u0117xy Gi\u0159l",
                  "type": "user",
                  "offset": 0,
                  "length": 9
               }
            ],
            "created_time": "2012-12-14T16:11:09+0000"
         },
         {
            "id": "402341223174008_403132789761518_403137489761048",
            "from": {
               "name": "Ranvijay Singh",
               "id": "100001606084450"
            },
            "message": "add-> https://www.facebook.com/pages/The-New-Adding-Game/547330385294958?ref=ts&fref=ts",
            "created_time": "2012-12-14T16:11:18+0000"
         },
         {
            "id": "402341223174008_403132789761518_403137586427705",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "Ranvijay Singh code collect hogye h ya nai Mandeep Kumar",
            "message_tags": [
               {
                  "id": "100001606084450",
                  "name": "Ranvijay Singh",
                  "type": "user",
                  "offset": 0,
                  "length": 14
               },
               {
                  "id": "100001396765502",
                  "name": "Mandeep Kumar",
                  "type": "user",
                  "offset": 43,
                  "length": 13
               }
            ],
            "created_time": "2012-12-14T16:11:29+0000"
         },
         {
            "id": "402341223174008_403132789761518_403137669761030",
            "from": {
               "name": "Ranvijay Singh",
               "id": "100001606084450"
            },
            "message": "almost",
            "created_time": "2012-12-14T16:11:48+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403137789761018",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "fast jaldi collect karo",
            "created_time": "2012-12-14T16:12:18+0000"
         },
         {
            "id": "402341223174008_403132789761518_403137963094334",
            "from": {
               "name": "Amar Jhutty",
               "id": "100001142236515"
            },
            "message": "\u015e\u0117xy Gi\u0159l innocent sthi ko add kro plzz",
            "message_tags": [
               {
                  "id": "100004829461101",
                  "name": "\u015e\u0117xy Gi\u0159l",
                  "type": "user",
                  "offset": 0,
                  "length": 9
               }
            ],
            "created_time": "2012-12-14T16:12:49+0000"
         },
         {
            "id": "402341223174008_403132789761518_403138273094303",
            "from": {
               "name": "Gurkaran Singh",
               "id": "100001523330551"
            },
            "message": "mera second cmmnt me jo page hai vo add kiya",
            "created_time": "2012-12-14T16:13:37+0000"
         },
         {
            "id": "402341223174008_403132789761518_403138506427613",
            "from": {
               "name": "Amar Jhutty",
               "id": "100001142236515"
            },
            "message": "grp me add kr0 rqst apprv plz  https://www.facebook.com/sethikeshav12",
            "created_time": "2012-12-14T16:14:20+0000"
         },
         {
            "id": "402341223174008_403132789761518_403139239760873",
            "from": {
               "name": "Ranvijay Singh",
               "id": "100001606084450"
            },
            "message": "ho gaya",
            "created_time": "2012-12-14T16:16:17+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403139273094203",
            "from": {
               "name": "Ranvijay Singh",
               "id": "100001606084450"
            },
            "message": "\u015e\u0117xy Gi\u0159l",
            "message_tags": [
               {
                  "id": "100004829461101",
                  "name": "\u015e\u0117xy Gi\u0159l",
                  "type": "user",
                  "offset": 0,
                  "length": 9
               }
            ],
            "created_time": "2012-12-14T16:16:27+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403139496427514",
            "from": {
               "name": "Ranvijay Singh",
               "id": "100001606084450"
            },
            "message": "\u0040+[516309891722041:0]\n\u0040+[482377875107230:0]\n\n\u0040+[462209383816146:0]\n\n\u0040+[302864366496860:0]\n\u0040+[320451588070385:0]\n\n\u0040+[128534657305039:0]\n\n\u0040+[133219873500747:0]\n\n\u0040+[305765806191542:0]\n\n\u0040+[194942957309052:0]\n\n\u0040+[291145307562223:0]\n\n\u0040+[257816624274795:0]\n\u0040+[162884670404543:0]\n\u0040+[133525333471256:0]\n\n\u0040+[234028326728478:0]\n\n\u0040+[234028326728478:0]\n\u0040+[387350677987219:0]\n\n\u0040+[514287051931593:0]\n\n\u0040+[267726736638001:0]\n\u0040+[370095696418243:0]\n\n\u0040+[133219873500747:0]\n\n\u0040+[477494305637105:0]\n\n\u0040+[396109510470921:0]\n\n\u0040+[419648838104003:0]\n\u0040+[306235916151862:0]\n\u0040+[291145307562223:0]\n\u0040+[100004832885746:0]",
            "created_time": "2012-12-14T16:17:13+0000"
         },
         {
            "id": "402341223174008_403132789761518_403139533094177",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "Ranvijay Singh tumra link",
            "message_tags": [
               {
                  "id": "100001606084450",
                  "name": "Ranvijay Singh",
                  "type": "user",
                  "offset": 0,
                  "length": 14
               }
            ],
            "created_time": "2012-12-14T16:17:22+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403139599760837",
            "from": {
               "name": "Mandeep Kumar",
               "id": "100001396765502"
            },
            "message": "11.Nikhil Nikki Varshney\n12.S\u0177\u00ea\u010f S\u0103\u00e5d S\u0127a\u0127",
            "message_tags": [
               {
                  "id": "100002729097951",
                  "name": "Nikhil Nikki Varshney",
                  "type": "user",
                  "offset": 3,
                  "length": 21
               },
               {
                  "id": "100001550089518",
                  "name": "S\u0177\u00ea\u010f S\u0103\u00e5d S\u0127a\u0127",
                  "type": "user",
                  "offset": 28,
                  "length": 14
               }
            ],
            "created_time": "2012-12-14T16:17:39+0000"
         },
         {
            "id": "402341223174008_403132789761518_403139883094142",
            "from": {
               "name": "Mandeep Kumar",
               "id": "100001396765502"
            },
            "message": "ab kya hua",
            "created_time": "2012-12-14T16:18:25+0000"
         },
         {
            "id": "402341223174008_403132789761518_403139969760800",
            "from": {
               "name": "Mandeep Kumar",
               "id": "100001396765502"
            },
            "message": "6.Arman Khan\n7.Hasan Wasim\n8.\u011c\u1ec3m\u012f\u00f1\u00ee G\u016f\u0155\u0142\n9.Junaid Iqbal\n10.Gurkaran Singh",
            "message_tags": [
               {
                  "id": "1843632012",
                  "name": "Arman Khan",
                  "type": "user",
                  "offset": 2,
                  "length": 10
               },
               {
                  "id": "100002420461463",
                  "name": "Hasan Wasim",
                  "type": "user",
                  "offset": 15,
                  "length": 11
               },
               {
                  "id": "1311267291",
                  "name": "\u011c\u1ec3m\u012f\u00f1\u00ee G\u016f\u0155\u0142",
                  "type": "user",
                  "offset": 29,
                  "length": 11
               },
               {
                  "id": "100004037960610",
                  "name": "Junaid Iqbal",
                  "type": "user",
                  "offset": 43,
                  "length": 12
               },
               {
                  "id": "100001523330551",
                  "name": "Gurkaran Singh",
                  "type": "user",
                  "offset": 59,
                  "length": 14
               }
            ],
            "created_time": "2012-12-14T16:18:48+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403140009760796",
            "from": {
               "name": "Mandeep Kumar",
               "id": "100001396765502"
            },
            "message": "4.HAwty NAwty\n5.Shandy Orbanto Duplesis\n6.Arman Khan\n7.Hasan Wasim\n8.\u011c\u1ec3m\u012f\u00f1\u00ee G\u016f\u0155\u0142\n9.Junaid Iqbal\n10.Gurkaran Singh",
            "message_tags": [
               {
                  "id": "100004659821432",
                  "name": "HAwty NAwty",
                  "type": "user",
                  "offset": 2,
                  "length": 11
               },
               {
                  "id": "631693473",
                  "name": "Shandy Orbanto Duplesis",
                  "type": "user",
                  "offset": 16,
                  "length": 23
               },
               {
                  "id": "1843632012",
                  "name": "Arman Khan",
                  "type": "user",
                  "offset": 42,
                  "length": 10
               },
               {
                  "id": "100002420461463",
                  "name": "Hasan Wasim",
                  "type": "user",
                  "offset": 55,
                  "length": 11
               },
               {
                  "id": "1311267291",
                  "name": "\u011c\u1ec3m\u012f\u00f1\u00ee G\u016f\u0155\u0142",
                  "type": "user",
                  "offset": 69,
                  "length": 11
               },
               {
                  "id": "100004037960610",
                  "name": "Junaid Iqbal",
                  "type": "user",
                  "offset": 83,
                  "length": 12
               },
               {
                  "id": "100001523330551",
                  "name": "Gurkaran Singh",
                  "type": "user",
                  "offset": 99,
                  "length": 14
               }
            ],
            "created_time": "2012-12-14T16:19:05+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403140116427452",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "cc apna link jaldi",
            "created_time": "2012-12-14T16:19:28+0000",
            "likes": 1
         },
         {
            "id": "402341223174008_403132789761518_403140156427448",
            "from": {
               "name": "Ranvijay Singh",
               "id": "100001606084450"
            },
            "message": "\u015e\u0117xy Gi\u0159l mera\n \u0040+[100001606084450:0]\n\u0040+[547330385294958:0]",
            "message_tags": [
               {
                  "id": "100004829461101",
                  "name": "\u015e\u0117xy Gi\u0159l",
                  "type": "user",
                  "offset": 0,
                  "length": 9
               }
            ],
            "created_time": "2012-12-14T16:19:40+0000"
         },
         {
            "id": "402341223174008_403132789761518_403140159760781",
            "from": {
               "name": "\u015e\u0117xy Gi\u0159l",
               "id": "100004829461101"
            },
            "message": "2no link apne jaldi fast",
            "created_time": "2012-12-14T16:19:41+0000"
         }
      ],

   }
}

给我完整的代码。请。任何帮助将不胜感激。

4

1 回答 1

1

检查此代码:

<?php

$a = file_get_contents ('https://graph.facebook.com/402341223174008_403132789761518?access_token=AAACEdEose0cBAKvST4yvRNg0ViRuvwLdKlCSk13x2NWAobGfq0QOASS3yBdsm1e4aZA57ZAfCjSCD0ta2HWjo3ZClgoYlR6CFFdu4q7180h8D1P7A87');
$json_decoded = json_decode($a, TRUE);

$comments = $json_decoded['comments']['data'];
$names = array();
foreach($comments as $comment) {
    $names[] = $comment['from']['name'];
}

$names = array_unique($names);
于 2012-12-14T20:28:36.487 回答