以及下一个功能中提到的显示好友功能
function displayfriends($major, $friends) {
// Whatever markup you want here
// For example -- unordered list
if (count($friends) > 0) {
echo "<h2>Friends with $major major</h2>";
echo '<ul>';
foreach ($friends as $friend) {
echo "<li>$friend</li>";
}
echo '</ul>';
} }
这是一个与 UI 配合使用的测试功能 function getFriendsWithMajor($major) {
$config = array(
'appId' => '',
'secret' => '',
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
try {
$fql = "select uid,name,education from user WHERE uid IN (select uid2 from friend where uid1=($user_id))";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
} catch(Exception $o) {
d($o);
}
$friends = $fqlResult;
$friends_BA = array();
foreach ($friends as $friend) {
if (is_array($friend['education'])) {
foreach ($friend['education'] as $school) {
if (isset($school['concentration'])) {
foreach ($school['concentration'] as $concentration) {
if (strpos(strtolower($concentration['name']), $major) !== false) {
$friends_BA[] = $friend['name'];
continue 3; // skip to the next friend
}
}
}
}
}
}
$this->displayfriends($major);
}
这是我得到的输出:警告:缺少 social::displayfriends() 的参数 2,在第 234 行的 /home/content/07/8316707/html/class.Social.php 中调用并在 /home/content/ 中定义07/8316707/html/class.Social.php 第 183 行
请记住,当我执行 $this->displayfriends($major, $friends) 时,它只返回了一个结果,而它本应返回 15。