0
請參見本文下面的PHP代碼:如何使用Facebook的API來提取出在好友列表中的位置和電子郵件
<?php
require '../src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxx',
'cookie' => true, // enable optional cookie support
));
try {
$me = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
}
if ($facebook->getSession()) {
$friendsLists = $facebook->api('/me/friends?fields=id,name,picture,locale,email');
$session = $facebook->getSession();
$query = "SELECT uid, name,locale,email,hometown_location FROM user WHERE uid = me() OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
$params = array(
'access_token' => $session['access_token'],
'secret' => $session['secret'],
'sig' => $session['sig'],
'query' =>$query
);
$url = "https://api.facebook.com/method/fql.query?" . http_build_query($params);
$data = simplexml_load_file($url);
//echo $me;
pr($data);
pr($friendsLists);
echo '<a href="' . $facebook->getLogoutUrl() . '">Logout</a>';
} else {
echo '<a href="' . $facebook->getLoginUrl() . '">Login</a>';
}
function pr($atr){
echo "<pre>";
print_r($atr);
echo "</pre>";
}
?>
我得到了放如下:
[user] => Array
(
[0] => SimpleXMLElement Object
(
[uid] => xxxxxxxxxxxxx
[name] => Deepak Rathi
[locale] => en_US
[email] => SimpleXMLElement Object
(
)
[hometown_location] => SimpleXMLElement Object
(
)
)
[1] => SimpleXMLElement Object
(
[uid] => xxxxxxxxxxxx
[name] => Aakriti Rovin Ranu
[locale] => en_GB
[email] => SimpleXMLElement Object
(
)
[hometown_location] => SimpleXMLElement Object
(
)
)
)
我的問題是「電子郵件'和'hometown_locations'在這裏是空的。我需要兩個信息在friendlist中。那裏需要做什麼..?請給予任何支持。
問候 迪帕克
掩蓋你的`appId`和`祕密`將是一個好主意! – Bartek 2011-01-06 13:41:19