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
+8.4k Golang : Format strings to SEO friendly URL example
+8.9k Golang : Print how to use flag for your application example
+2.8k Java : Random alphabets, alpha-numeric or numbers only string generator
+13.4k Golang : Accurate and reliable decimal calculations
+3.6k Chrome : How to block socketloop.com links in Google SERP?
+34.9k Golang : Display float in 2 decimal points and rounding up or down
+5.5k Golang : Derive cryptographic key from passwords with Argon2
+4.6k Python : Print unicode escape characters and string
+19.5k Golang : Create and resolve(read) symbolic links
+6k Golang : Get Alexa ranking data example
+8.6k Golang : Identifying Golang HTTP client request
+13k Golang : Overwrite previous output with count down timer