0

这是我使用 Facebook SDK 实现的 facebook 登录功能。

<script type="text/javascript">
window.fbAsyncInit = function () {        
    // Initialize the SDK upon load
    FB.init({
        appId: '1xxxxxxxxxxxx', // App ID
        channelUrl: '//' + window.location.hostname + '//Home/Index', 
        scope: 'id,name,gender,user_birthday,email,first_name,last_name,access_token', 
        status: true,
        cookie: true, 
        xfbml: true  
    });
    // listen for and handle auth.statusChange events
    FB.Event.subscribe('auth.statusChange', OnLogin);
};

// This method will be called after the user login into facebook.
function OnLogin(response) {
    if (response.authResponse) {
        var access_token = FB.getAuthResponse()['accessToken'];
        $('#AccessToken').attr('value', access_token);

        $("#AuthenticatedWithFacebook").attr("value", true);

        FB.api('/me', LoadValues);
    }
    else {
        $("#AuthenticationToken").removeAttr('value');

        $("#AuthenticatedWithFacebook").attr("value", false);
    }
}

//This method will load the values to the labels
function LoadValues(me) {
    if (me.id) {
        $("#UserId").attr("value", me.id);
        $("#AuthenticationToken").attr("value", "facebook/" + me.id);
        $("#FirstName").attr("value", me.first_name);
        $("#LastName").attr("value", me.last_name);
        $("#EmailAddress").attr("value", me.email);
    }
}
</script>

<script>(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#xfbml=1&appId=1xxxxxxxxxxxxxx";    
    fjs.parentNode.insertBefore(js, fjs);
 }(document, 'script', 'facebook-jssdk'));
 </script>

登录弹出窗口工作正常,但登录后我得到以下异常:

在http://static.ak.fbcdn.net/rsrc.php/v2/yQ/r/Yax99g-1J46.js 0x80070005中的第 38 行第 184 列引发异常 - JavaScript 运行时错误:访问被拒绝。

我正在http://localhost:59777/我的 Facebook 应用程序中配置的 localhost ( ) 上进行测试。

4

0 回答 0