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.1k Golang : Reverse text lines or flip line order example
+3.7k Mac OSX : Get disk partitions' size, type and name
+4.7k Golang : Error handling methods
+6.4k Golang : Lock executable to a specific machine with unique hash of the machine
+3.8k Linux/MacOSX : How to symlink a file?
+11.9k Golang : Handle or parse date string with Z suffix(RFC3339) example
+19.2k Golang : Saving private and public key to files
+6.3k Golang : Check to see if *File is a file or directory
+8.5k Golang : Eroding and dilating image with OpenCV example
+6.3k Golang : File system scanning
+3.9k Golang : Customize scanner.Scanner to treat dash as part of identifier
+7.4k Golang : Generate Datamatrix barcode