所以我正在尝试使用fb graph api来收集有关facebook朋友的一些信息,项目范围取决于这里的所有字段(根据数据创建排序算法)。 / p>
不幸的是,当我收集所有数据(这需要永远)时,朋友数据的几个字段都丢失了。我预计有些人会失踪,但超过一半的人没有给我位置信息,所有的宗教信息都没有显示出来。我检查了一些朋友个人的Facebook页面,数据在那里,并作为他们的朋友透露给我(例如他们有一个当前的位置)。有什么我做错了,或者只是我不能做的事情。如果有另一种方式来收集这个,我愿意接受建议。任何想法都会很棒!
$config = array(
'appId' => '###############',
'secret' => '########################',
'allowSignedRequest' => false // optional but should be set to false for non-canvas apps
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
?>
<html>
<head></head>
<body>
<?php
if($user_id) {
try {
//User Data
$user_profile = $facebook->api('/me','GET');
$locationId = $user_profile['location']['id'];
$location = $user_profile['location']['name'];
$platform = $facebook->api('/'.$locationId,'GET');
date_default_timezone_set('UTC');
echo "Name: " . $user_profile['name'] . "<br />";
echo "Gender: " . $user_profile['gender'] . "<br />";
echo "Birthday: " . $user_profile['birthday']. "<br />";
$date = explode("/", $user_profile['birthday']);
$age = date("Y") - $date[2];
echo "Age: " . $age . "<br />";
echo "Religion: " . $user_profile['religion']. "<br />";
echo "Hometown: " . $user_profile['hometown']['name']. "<br />";
echo "Location: " . $location . "<br />";
echo "Longitude: " . $platform['location']['longitude']. "<br />";
echo "Latitude: " . $platform['location']['latitude']. "<br />";
//Friend Data
$friends = $facebook->api('/me/friends', 'GET');
echo "<br />";
echo "Friend Test <br />";
foreach($friends["data"] as $value) {
$c_id = $value['id'];
echo $c_id. "<br />";
$c_friend = $facebook->api('/'.$c_id);
echo "Name: ". $c_friend['name'] . "<br />";
echo "Gender: ". $c_friend['gender']. "<br />";
echo "Birthday: ". $c_friend['birthday']. "<br />";
echo "Religion: ". $c_friend['religion']."<br />";
echo "Hometown: ". $c_friend['hometown']['name']. "<br />";
echo "Location: ". $c_friend['location']['name']. "<br />";
$c_locationId = $c_friend['location']['id'];
if($c_locationId)
{
$c_platform = $facebook->api('/'.$c_locationId,'GET');
echo "Longitude: ". $c_platform['location']['longitude']. "<br />";
echo "Latitude: ". $c_platform['location']['latitude']. "<br />";
}
echo "<br />";
}
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl(array("scope" => "user_religion_politics,user_birthday,user_hometown,user_location,friends_religion_politics,friends_birthday,friends_hometown,friends_location"));
echo "Place 1 <br />";
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$login_url = $facebook->getLoginUrl(array("scope" => "user_religion_politics,user_birthday,user_hometown,user_location,friends_religion_politics,friends_birthday,friends_hometown,friends_location"));
echo "Place 2<br />";
echo 'Please <a href="' . $login_url . '">login.</a>';
}
?>
</body>
</html>