2011-08-07 214 views
0
<?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>"; 

?> 

我該如何運行它?我不知道新的代碼。等待您的幫助,請:(Facebook好友列表

回答

2

您需要使用PHP SDK for the Facebook API

require 'php-sdk/src/facebook.php'; 

$facebook = new Facebook(array(
    'appId' => 'YOUR_APP_ID', 
    'secret' => 'YOUR_APP_SECRET', 
)); 

要獲取好友列表:

$friendsLists = $facebook->api('/me/friends'); 

foreach ($friendsLists as $friends) { 
    foreach ($friends as $friend) { 
    $id = $friend['id']; 
    $name = $friend['name']; 
    } 
} 
+0

你好 謝謝你的幫助 我想把我的朋友的照片和姓名顯示爲10. 我該怎麼辦? 獲得許可需要哪些權限? – Mustafa

2

我延長了答案通過以上對拉夫包括限制器和洗牌機

$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; 
    } 
}