2013-08-24 52 views
1

我目前正在學習使用Facebook Javascript SDK登錄用戶。起初,我不需要詢問一個電子郵件地址,但現在我可以。我嘗試了幾個我從其他人那裏讀到的東西,但沒有爲我工作。我之前使用的代碼可能有問題嗎?添加scope: "email"的最佳方法是什麼?Facebook JavaScript SDK:無法請求訪問電子郵件

這是我迄今爲止所使用的代碼:

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

爲什麼用戶不能在問讓我的應用程序訪問自己的電子郵件地址?

在此先感謝, 大衛。

回答

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

相關問題