Steve
Steve

Reputation: 53

How to read the birthday_date from the Facebook API

I have been chasing my tail on this! And it should be so simple!!

I have an app in FaceBook that is working fine. However, I need to get the user's birth date. I have successfully got the request for extended permissions, but cannot get the birthday_date out and into a variable/store in database.

<?php
require_once('facebook.php');
$facebook = new Facebook(array(
'appId'  => 'xxxxx',
'secret' => 'yyyyyyy',
'cookie' => true
));
if ($facebook->getSession()) { 
$uid = $facebook->getUser();
$fbme = $facebook->api('/me');
} else {
$params = array(
    'fbconnect'=>0,
    'canvas'=>1,
    'req_perms'=>'publish_stream','email','user_location','user_birthday'
);
$loginUrl = $facebook->getLoginUrl($params);
print "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}
$session = $facebook->getSession();
$token = $session['access_token'];

I would be very grateful if someone could show me the PHP code that reads the extended permissions and places the results into variables.

Thanks Steve

Upvotes: 3

Views: 14437

Answers (4)

Sean Harding
Sean Harding

Reputation: 11

This came in handy but if you're wondering why it's not working where it should be, try removing the app from your personal page and re-authorise the app.

"Account->Privacy Settings->'Apps and Websites'->Edit your settings" remove your app from the list.

Upvotes: 1

mutkan
mutkan

Reputation: 954

this works in Linux

NOW=$(date +"%m/%d")

curl "https://api.facebook.com/method/fql.query?access_token=[ACCESS_TOKEN]&query=SELECT%20first_name,uid%20from%20user%20where%20uid%20in%20(SELECT%20uid2%20from%20friend%20where%20uid1=[YourFaceID])AND%20substr(birthday_date,0,5)%20==%20'$NOW'"

Upvotes: 0

Steve
Steve

Reputation: 53

The section of code...

if ($facebook->getSession()) {
$uid = $facebook->getUser();          
$fbme = $facebook->api('/me');          
} else {          
$params = array(     
'fbconnect'=>0,
'canvas'=>1,    
'req_perms'=>'publish_stream','email','user_location','user_birthday' 
); 

Should read....

if ($facebook->getSession()) {
$uid = $facebook->getUser();          
$fbme = $facebook->api('/me');          
} else {          
$params = array(     
'fbconnect'=>0,
'canvas'=>1,    
'req_perms'=>'publish_stream,email,user_location,user_birthday'
); 

(note change to 'req_perms' line) The birthday can then be read as

$birthday=$fbme['birthday'];

However, if the user has not shared the birthday information then $fbme['birthday'] may return NULL.

This problem was caused by the line of code requesting extended permissions, but I thought I had the extended permissions because I could publish a stream and had access to the email address.

Thanks also to Joshua! My own date of birth is only viewable to My Friends and still did not display once I corrected the coding.

Facebook API - you just gotta love it!!!

Upvotes: 2

Joshua Smith
Joshua Smith

Reputation: 6621

there is no birthday_date it's only birthday (in the new api).

http://developers.facebook.com/docs/reference/api/user

but it may return null,even if you have perms. See this (not really a) bug:

http://bugs.developers.facebook.net/show_bug.cgi?id=12166

Summary of it is (it's not really a bug): Your user may still have revoked your access to this data.

Upvotes: 3

Related Questions