简体   繁体   English

解析共同朋友响应PHP JSON

[英]Parse Mutual Friends response PHP JSON

I am using facebook graph api to access mutual friend list using PHP Here's how I am doing it 我正在使用Facebook graph api使用PHP访问共同朋友列表这是我的工作方式

$url  = "https://graph.facebook.com/me/mutualfriends/123456788?access_token=1457856";

$user = json_decode(file_get_contents($jsonurl));

I am now printing the result via print_r($user->data) and following is the output 我现在通过print_r($ user-> data)打印结果,以下是输出

Array
(
    [0] => stdClass Object
        (
            [name] => XYZ
            [id] => 123
        )

)
Array
(
    [0] => stdClass Object
        (
            [name] => YZX
            [id] => 235
        )

)

I need to get name and Id of the mutual friends from the above resultset using PHP 我需要使用PHP从上述结果集中获取共同朋友的姓名和ID

What should be the next step for this? 下一步应该做什么?

It would be the same like $user->data : 就像$user->data

foreach($user->data as $user) {
   echo "name: ".$user->name."<br>";
   echo "id: ".$user->id."<hr>";
}

I have tested this on the following data: 我已经对以下数据进行了测试:

stdClass Object
(
    [data] => Array
        (
            [0] => stdClass Object
                (
                    [id] => ID
                    [name] => Name
                )

            [1] => stdClass Object
                (
                    [id] => ID
                    [name] => Name
                )

        )

)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM