开发者

Facebook API how to get User Pages

开发者 https://www.devze.com 2023-03-24 23:30 出处:网络
I am using the following code to grab info for the Facebook user. Is there a way to get the user Pages (if the user has one or more Facebook Pages) and the IDs of these pages?

I am using the following code to grab info for the Facebook user.

Is there a way to get the user Pages (if the user has one or more Facebook Pages) and the IDs of these pages?

$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开发者_C百科_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;
}
}


If you asking how to get additional user profiles, of a single user, based on their Facebook Id: the answer is you can't. Facebook mandates one profile per user. And while in real life a user can have multiple profiles, there is no reliable means of extracting that data from the graph.

However, if you're asking how to get the ids of pages the user admins then use:

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

this will require a valid access token for the given user.

0

精彩评论

暂无评论...
验证码 换一张
取 消