2013-06-22 64 views
0

對於我的Facebook畫布應用程序,我一直在嘗試訪問用戶電子郵件。即使我要求它,它仍然不顯示(生日,這也是一個額外的許可,確實顯示)。 (在addscope功能)Facebook JS api:儘管要求權限,但仍未收到用戶電子郵件

<html> 
<head></head> 
<body> 
<div id="fb-root"></div> 
<script> 
    window.fbAsyncInit = function() { 
    FB.init({ 
    appId  : '--------------', // App ID 
    channelUrl : 'http://www.---------.com/channel.html', // Channel File 
    status  : true, // check login status 
    cookie  : true, // enable cookies to allow the server to access the session 
    xfbml  : true // parse XFBML 
    }); 


    FB.Event.subscribe('auth.statusChange', function(response) { 
     if(response.status === 'connected') 
      { 
       console.log('Hello there!'); 
       addScope(); 

      } 
     else if(response.status === 'not_authorized') 
      { 
       console.log('not authorized'); 
       addScope(); 

      } 
     else 
      { 
       console.log('not logged in'); 
       addScope(); 
      } 
    }); 



    FB.Event.subscribe('auth.authResponseChange', function(response) { 
    // Here we specify what we do with the response anytime this event occurs. 
    if (response.status === 'connected') { 
     // ... 
    } else if (response.status === 'not_authorized') { 
     // ... 

    } else { 
     //... 
    } 
    }); 
    }; 

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


    function addScope() 
    { 
     FB.login(function(response) { 
    if (response.authResponse) { 
    console.log('Welcome! Fetching your information.... '); 
    FB.api('/me', function(response) { 
     console.log('In addscope function, ' + response.email + response.birthday); 
    }); 
    } else { 
    console.log('User cancelled login or did not fully authorize.'); 
    } 
},{scope: 'email,user_birthday'}); 

    } 
</script> 

</body> 
</html> 

回答

1

據我所看到的,並提供有被其他地方的「addScope」方法被調用拋出任何錯誤,你的代碼是正確的。只要確保實際上有一個返回值(即用戶有生日和電子郵件,否則你將無法得到它,如在此所述:https://developers.facebook.com/docs/reference/api/user/

我使用FB API並沒有問題在使用用戶訪問令牌的同時獲取電子郵件和其他字段。

2

,看是否正確的權限正在通過代碼設置一個有效的方法是使用下面的代碼(更改要在查詢部分來檢查字段):

FB.api({ method: 'fql.query', query: 'SELECT user_status,friends_status,user_photos,friends_photos,user_location,friends_location FROM permissions WHERE uid=me()' }, function(resp) { 
for(var key in resp[0]) { 
    if(resp[0][key] === "1") 
     console.log(key+' is granted'); 
    else 
     console.log(key+' is not granted'); 
} 
}); 

這是用戶可能沒有授予訪問電子郵件ID的權限。

0

刪除此:

FB.Event.subscribe('auth.authResponseChange', function(response) { 
// Here we specify what we do with the response anytime this event occurs. 
if (response.status === 'connected') { 
    // ... 
} else if (response.status === 'not_authorized') { 
    // ... 

} else { 
    //... 
} 
}); 
}; 

,然後再試一次

相關問題