midhul
06-07-2010, 05:11 PM
Hey guys,
This is not any topic realred to the core depths of facebook connect, but simple one that any non confused php programmer can answer :)
Please refer to this doc regarding single sign on feature of fb connect: http://developers.facebook.com/docs/guides/web
actually I was building an app which uses fb login button then requests user email and send it to another form to process.
But I am abit confused about how to request the user data after the log on has been made.
Here is the code:
<?php
define('FACEBOOK_APP_ID', 'your application id');
define('FACEBOOK_SECRET', 'your application secret');
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($cookie) { ?>
Your user ID is <?= $cookie['uid'] ?>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
<?php
$user = json_decode(file_get_contents(
'https://graph.facebook.com/me?wrap_access_token=' .
$cookie['oauth_access_token']))->me;
register_user($user->id, $user->email, $user->name, $user->username,
$user->birthday_date);
echo $user->email;
?>
</body>
</html>
as you can see after requesting log on with the fb connect button, I have use a php code to request and echo the users email:
$user = json_decode(file_get_contents(
'https://graph.facebook.com/me?wrap_access_token=' .
$cookie['oauth_access_token']))->me;
register_user($user->id, $user->email, $user->name, $user->username,
$user->birthday_date);
echo $user->email;
I mean I used echo $user->email, but it is not working :(
I think I have used the wrong variable.
Can some please help me and tell me how to do it?
Thanks alot in advance :)
This is not any topic realred to the core depths of facebook connect, but simple one that any non confused php programmer can answer :)
Please refer to this doc regarding single sign on feature of fb connect: http://developers.facebook.com/docs/guides/web
actually I was building an app which uses fb login button then requests user email and send it to another form to process.
But I am abit confused about how to request the user data after the log on has been made.
Here is the code:
<?php
define('FACEBOOK_APP_ID', 'your application id');
define('FACEBOOK_SECRET', 'your application secret');
function get_facebook_cookie($app_id, $application_secret) {
$args = array();
parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args);
ksort($args);
$payload = '';
foreach ($args as $key => $value) {
if ($key != 'sig') {
$payload .= $key . '=' . $value;
}
}
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($cookie) { ?>
Your user ID is <?= $cookie['uid'] ?>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({appId: '<?= FACEBOOK_APP_ID ?>', status: true,
cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
</script>
<?php
$user = json_decode(file_get_contents(
'https://graph.facebook.com/me?wrap_access_token=' .
$cookie['oauth_access_token']))->me;
register_user($user->id, $user->email, $user->name, $user->username,
$user->birthday_date);
echo $user->email;
?>
</body>
</html>
as you can see after requesting log on with the fb connect button, I have use a php code to request and echo the users email:
$user = json_decode(file_get_contents(
'https://graph.facebook.com/me?wrap_access_token=' .
$cookie['oauth_access_token']))->me;
register_user($user->id, $user->email, $user->name, $user->username,
$user->birthday_date);
echo $user->email;
I mean I used echo $user->email, but it is not working :(
I think I have used the wrong variable.
Can some please help me and tell me how to do it?
Thanks alot in advance :)