Reputation: 1
<?php
require_once 'facebook/facebook.php';
$appapikey = 'xx';
$appsecret = 'yy';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
echo "<p>Hello, <fb:name uid=\"$user_id\" useyou=\"false\" />!</p>";
echo "<p>Friends:";
$friends = $facebook->api_client->friends_get();
$friends = array_slice($friends, 0, 15);
foreach ($friends as $friend) {
echo "<br><fb:profile-pic uid='$friend'><fb:name uid=\"$friend\" useyou=\"false\" /></fb:profile-pic>";
}
echo "</p>";
?>
How can I run it? I do not know the new codes. Waiting for your help please :(
Upvotes: 0
Views: 853
Reputation: 21
I extended the answer above by Gaurav to include a limiter and shuffler.
$i = 0;
foreach ($friendsLists as $friends) {
shuffle($friends);
foreach ($friends as $friend) {
$id = $friend['id'];
$name = $friend['name'];
echo $name;
echo "<img src='http://graph.facebook.com/" . $id ."/picture'><br>";
if (++$i == 5) break;
}
}
Upvotes: 2
Reputation: 5416
You need to use the PHP SDK for the Facebook API for this.
require 'php-sdk/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'YOUR_APP_ID',
'secret' => 'YOUR_APP_SECRET',
));
To get the list of friends:
$friendsLists = $facebook->api('/me/friends');
foreach ($friendsLists as $friends) {
foreach ($friends as $friend) {
$id = $friend['id'];
$name = $friend['name'];
}
}
Upvotes: 2