Facebook Graph API : Parsing the output

I am trying to get the names of my friends using FB Graph API with this call :

$friends = file_get_contents('https://graph.facebook.com/me/friendsaccess_token='.$session["access_token"]);

echo "Friends : $friends\n";

This gives me a list of the form :

{"data":[{"name":"ABC XYZ","id":"12212839"},{"name":"PQR GHI","id":"5004678"}]}

I want to be able to store only the NAMES in an array. How do I use $friends to get the names ? Something like $friends['name'] doesn't seem to work.

Please help. Thank you.

Answers


$friends = json_decode($friends);
foreach($friends['data'] as $friend)
{
     echo $friend['name'];
}

The return is a json object, you need to decode it. Although I strongly urge you to use an SDK such as http://github.com/facebook/php-sdk/

If this doesn't work try:

$friends = json_decode($friends);
foreach($friends->data as $friend)
{
     echo $friend->name;
}

Need Your Help

UAC and Windows box selections in Windows

python windows com

So I'm using Python (though another language suggestion like C# or VB is fine too). I want to have a program launch an EXE file installer, and then tell that installer that it is alright to run the

memory allocation for 2D array of pointers

c pointers

I am getting super confused with dynamic memory allocation and deletion of a 2D array of pointers.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.