2013-02-06 84 views
0
<div id="fb-root"> 
</div> 
<script> 
    window.fbAsyncInit = function() { 
     FB.init({ 
      appId: 'myappid', // App ID 
      status: true, // check login status 
      cookie: true, // enable cookies to allow the server to access the session 
      xfbml: true // parse XFBML 
     }); 

     // Additional initialization code here 
     FB.Event.subscribe('auth.authResponseChange', function (response) { 
      if (response.status === 'connected') { 
       // the user is logged in and has authenticated your 
       // app, and response.authResponse supplies 
       // the user's ID, a valid access token, a signed 
       // request, and the time the access token 
       // and signed request each expire 
       var uid = response.authResponse.userID; 
       var accessToken = response.authResponse.accessToken; 

       // TODO: Handle the access token 
       // Do a post to the server to finish the logon 
       // This is a form post since we don't want to use AJAX 
       var form = document.createElement("form"); 
       form.setAttribute("method", 'post'); 
       form.setAttribute("action", 'facebooklogin.aspx'); 

       var field = document.createElement("input"); 
       field.setAttribute("type", "hidden"); 
       field.setAttribute("name", 'accessToken'); 
       field.setAttribute("value", accessToken); 
       form.appendChild(field); 

       document.body.appendChild(form); 
       form.submit(); 

      } else if (response.status === 'not_authorized') { 
       // the user is logged in to Facebook, 
       // but has not authenticated your app 
      } else { 
       // the user isn't logged in to Facebook. 
      } 
     }); 
    }; 
    // Load the SDK Asynchronously 
    (function (d) { 
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0]; 
     if (d.getElementById(id)) { return; } 
     js = d.createElement('script'); js.id = id; js.async = true; 
     js.src = "//connect.facebook.net/en_US/all.js"; 
     ref.parentNode.insertBefore(js, ref); 
    } (document)); 
</script> 
<div class="fb-login-button" data-show-faces="false" 
    data-width="400" data-max-rows="1"> 
</div> 

的.cs代碼爲C#。用戶的電子郵件Facebook登錄不予退還

 var accessToken = HttpContext.Current.Request["AccessToken"]; 
     var client = new FacebookClient(accessToken); 
     var me = client.Get("me") as IDictionary<string, object>; 
     string firstName = (string)me["first_name"]; 
     string lastName = me["last_name"].ToString(); 
     string id = me["id"].ToString(); 
     string email=me["email"].ToString(); 

其他值可以得到,除了email

回答

0

您尚未添加權限訪問email

更改您的登錄代碼這樣:

<div class="fb-login-button" data-show-faces="false" 
data-width="400" data-max-rows="1" scope="email"> 
相關問題