Facebook : Getting the friends list with PHP return JSON format
Problem :
How to get friends list in Facebook with PHP in Json format?
Solution :
Use Facebook SDK https://graph.facebook.com/me/friends
Below is a code fragment in CodeIgniter/PHP on achieving the desired result.
<?php
$fb_config = array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxx',
'cookie' => TRUE
);
$this->load->library('facebook', $fb_config);
$user = $this->facebook->getUser();
if ($user) {
try {
$data['user_profile'] = $this->facebook->api('/me');
} catch (FacebookApiException $e) {
$user = null;
}
}
if ($user) { //ok, the user exist, proceed
$access_token = $this->facebook->getAccessToken();
$file = file_get_contents('https://graph.facebook.com/me/friends?access_token=' . $access_token);
$jsonFriends = json_decode($file, true);
$Friends = $jsonFriends['data'];
}
?>
The important part is to save the returned result from Facebook into a file and the decode the result with Json decode function in PHP.
Hope this solution will assist your project.
See also : Get Facebook friends working in same company
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+4.4k PHP : Fix Call to undefined function curl_init() error
+7k Swift : Convert (cast) String to Float
+4.5k Unix/Linux : How to find out the hard disk size?
+7.9k Golang : HTTP Routing with Goji example
+16.8k Golang : Check if a directory exist or not
+50.5k Golang : How to get time in milliseconds?
+33.8k Golang : Get file last modified date and time
+17.9k Golang : How to get own program name during runtime ?
+5.7k Golang : Muxing with Martini example
+7.1k Golang : Number guessing game with user input verification example
+15.7k Golang : How to tell if a file is compressed either gzip or zip ?
+6k Golang : Get Alexa ranking data example