Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add data-scope variables to a facebook login button

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!

like image 678
user1048676 Avatar asked Feb 02 '12 23:02

user1048676


People also ask

What is the login button?

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.


3 Answers

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>

like image 118
DMCS Avatar answered Oct 20 '22 06:10

DMCS


<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/

like image 6
user2299743 Avatar answered Oct 20 '22 08:10

user2299743


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/

like image 2
Sándor Tóth Avatar answered Oct 20 '22 08:10

Sándor Tóth