All, I'm using the code that facebook provides but here is what I'm using:
<?php
define('123', '123');
//uses the PHP SDK. Download from https://github.com/facebook/php-sdk
require 'facebook.php';
$facebook = new Facebook(array(
'appId' => '123',
'secret' => '12344556',
));
$userId = $facebook->getUser();
?>
<html>
<body>
<?php if ($userId) {
//$userInfo = $facebook->api('/' + $userId);
$userInfo = $facebook->api('/me');
print_r($userInfo);
?>
Your email address is: <?= $userInfo['email'] ?>
<?php } else { ?>
<div id="fb-root"></div>
<fb:login-button></fb:login-button>
<?php } ?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '<?= 123?>',
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
</body>
</html>
If I need someone's email address when they are logging in I want to add that data-scope variable so if it's the first time they login that it prompts them to give me that permission. Where do I add that to the code above? Do I have to put it in the login-button?
Please help!
Thanks!
When inserted properly, a login button appears on the Web page. Clicking the login button opens a login window in which a user enters the username and password.
Per http://developers.facebook.com/docs/reference/plugins/login/
Use the scope
attribute to tell the dialog what permissions to prompt for.
<fb:login-button scope="email"></fb:login-button>
<fb:login-button data-scope='email'></fb:login-button>
This is more like the example Facebook uses on https://developers.facebook.com/docs/reference/plugins/login/
You have to set the scope attribute, to control the auth process.
<fb:login-button scope='email'></fb:login-button>
More information about scope:
https://developers.facebook.com/docs/reference/api/permissions/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With