Reputation: 2005
require 'src/facebook.php';
$app_id = 'My App Id';
$app_secret = 'My App Secret Id';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
));
$user = $facebook->getUser();
if ($user) {
$user_albums = $facebook->api('/me/friends?fields=id,name,birthday');
}
if ($user) {
$params = array( 'next' => 'http://localhost/friends_bday/logout.php?logout=1' );
$logoutUrl = $facebook->getLogoutUrl($params);
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_photos'
));
}
The above code only provides friends id and name but not birthdays. I have done some researching and was unsuccessful in finding a solution.
Upvotes: 1
Views: 1314
Reputation: 356
You probably need to request permission of the user to access the birthday information of their friends. The Facebook permission you are looking for is 'friends_birthday'.
Request the user their access token with the above permission and set the access token.
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true,
)
);
$facebook->setAccessToken($userAccessToken);
$user = $facebook->getUser();
if ($user) {
$user_albums = $facebook->api('/me/friends?fields=id,name,birthday');
}
if ($user) {
$params = array( 'next' => 'http://localhost/friends_bday/logout.php?logout=1' );
$logoutUrl = $facebook->getLogoutUrl($params);
} else {
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'user_photos, friends_birthday'
));
}
Actually I think you just have to add friends_birthday to the scope.
Upvotes: 2