1

我目前正在学习使用 Facebook Javascript SDK 来登录用户。起初我不需要询问电子邮件地址,但现在我需要。我尝试了几件从其他人那里读到的东西,但对我没有任何帮助。我之前使用的代码可能有问题吗?添加的最佳方法是scope: "email"什么?

这是我到目前为止使用的代码:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>A Facebook login test!</title>
    <link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
    <style type="text/css">
        h1 {font-family: 'Roboto', sans-serif;}
    </style>
</head>

<body>
    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        // init the FB JS SDK
        FB.init({
          appId      : '{{ FACEBOOK_APP_ID }}',                 // App ID from the app dashboard
          channelUrl : '{{ DOMAIN }}/channel.html',                 // Channel file for x-domain comms
          status     : true,                                    // Check Facebook Login status
            cookie    : true,                                               // enable cookies to allow the server to access the session       
          xfbml      : true                                     // Look for social plugins on the page
        });

      // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
      // for any authentication related change, such as login, logout or session refresh. This means that
      // whenever someone who was previously logged out tries to log in again, the correct case below 
      // will be handled. 
      FB.Event.subscribe('auth.authResponseChange', function(response) {
      // Here we specify what we do with the response anytime this event occurs. 
        if (response.status === 'connected') {
                  // The response object is returned with a status field that lets the app know the current
                  // login status of the person. In this case, we're handling the situation where they 
                  // have logged in to the app.

          window.location = "/fblogin";
            } 
        });
      };

      // Load the SDK asynchronously
      (function(d, s, id){
         var js, fjs = d.getElementsByTagName(s)[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement(s); js.id = id;
         js.src = "//connect.facebook.net/en_US/all.js";
         fjs.parentNode.insertBefore(js, fjs);
       }(document, 'script', 'facebook-jssdk'));


    </script>

    <h1>This is the Facebook and Google+ login test.</h1>
    <br>
    <fb:login-button show-faces="true" width="200" max-rows="1" scope: "email"></fb:login-button>
    <br>

为什么没有要求用户让我的应用访问他的电子邮件地址?

在此先感谢大卫。

4

1 回答 1

0

你写了 :<fb:login-button show-faces="true" width="200" max-rows="1" scope: "email">

试试这个:<fb:login-button show-faces="true" width="200" max-rows="1" scope= "email">

于 2013-08-25T12:25:38.743 回答