2011-08-04 130 views
3

我正在使用以下代碼來獲取Facebook用戶的信息。Facebook API如何獲取用戶頁面

有沒有辦法讓用戶頁面(如果用戶有一個或多個Facebook頁面)和這些頁面的ID?

$user = $_POST['uid']; //the returned user ID from Facebook 
$key = $_POST['usid']; //the returned session ID from Facebook 
$accesstoken = $_POST['accesstoken']; //the returned accesstoken from Facebook 
$image = "http://graph.facebook.com/" .$user ."/picture?type=large"; //Facebook Profile Picture 
$name = json_decode(file_get_contents('https://graph.facebook.com/' . $user))->name; //Name of the user account on Facebook 
$link = json_decode(file_get_contents('https://graph.facebook.com/' . $user))->link; //Link of the user profile on Facebook 
$gender = json_decode(file_get_contents('https://graph.facebook.com/' . $user))->gender; //Gender of the user on Facebook 
$locale = json_decode(file_get_contents('https://graph.facebook.com/' . $user))->locale; //Location of the user on Facebook 
$url = "https://graph.facebook.com/". $user ."/feed?limit=1&access_token=".$accesstoken; //We get the latest status update on the Facebook Wall 
$json = file_get_contents($url); 
$jsonData = json_decode($json); 
foreach($jsonData->data as $val) { 
if($val->from->id == $user) { 
$statusmessage = $val->message; //Finally we got the latest status update if there is one on The Facebook Wall 
break; 
} 
} 

回答

5

如果你問如何獲得額外的用戶配置文件,單個用戶,基於他們的Facebook ID:答案是你不能。 Facebook爲每個用戶授權一個配置文件。在現實生活中,用戶可以擁有多個配置文件,但沒有可靠的方法從圖表中提取數據。

不過,如果你問如何獲得頁面的ID的用戶管理員然後使用:

https://graph.facebook.com/USER_ID/accounts 

這將需要對給定用戶的有效訪問令牌。

相關問題