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
+5.1k Golang : How to write backslash in string?
+24k Golang : Convert uint value to string type
+34.2k Golang : How to split or chunking a file to smaller pieces?
+12.6k Golang : Check if an integer is negative or positive
+5.8k Golang : Get expvar(export variables) to work with multiplexer
+4.5k Golang : Intercept, inject and replay HTTP traffics from web server
+4.6k Clean up Visual Studio For Mac installation failed disk full problem
+3.9k Golang : A program that contain another program and executes it during run-time
+11.5k Golang : Exit, terminating or aborting a program
+15.4k Golang : Send email and SMTP configuration example
+3.9k Linux : How to set root password in Linux Mint
+5.8k Golang : Find the shortest line of text example