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
+7.7k Golang : Test if an input is an Armstrong number example
+36.4k Golang : Validate IP address
+5.4k Golang : Stop goroutine without channel
+10.5k RPM : error: db3 error(-30974) from dbenv->failchk: DB_RUNRECOVERY: Fatal error, run database recovery
+21.4k Golang : How to read float value from standard input ?
+9.4k Golang : Get all countries currencies code in JSON format
+13.9k Golang : concatenate(combine) strings
+14.1k Elastic Search : Mapping date format and sort by date
+13.7k Golang : Convert spaces to tabs and back to spaces example
+12.9k Golang : Get terminal width and height example
+11.4k Golang : Change date format to yyyy-mm-dd
+8.5k Golang : Another camera capture GUI application with GTK and OpenCV