Facebook oauth弹出窗口被浏览器阻止

时间:2015-12-04 14:09:33

标签: facebook oauth-2.0 popup

请帮助,我的代码中有什么问题,因为浏览器阻止会弹出Facebook窗口。我不知道。在某些浏览器中它被阻止,有时候还可以。我应该找出解决方法。

/*facebook oauth*/
$('#oauth_facebook').on('click', function (event) {
    event.preventDefault();
    window.fbAsyncInit = function () {

        FB.init({
            appId: 'ххххххххххх',
            cookie: true,
            xfbml: true,
            oauth: true
        });

        FB.getLoginStatus(function (response) {
            console.log('sucsess');
            if (response.status === 'connected') {
                var accessToken = response.authResponse.accessToken;
                var userID = response.authResponse.userID;
                var userName, userEmail;
                var url = '/me?fields=name,email,picture.width(300).height(300)';
                var avatar;
                FB.api(url, function (response) {
                    userName = response.name;
                    userEmail = response.email;
                    avatar = response.picture.data.url;
                  
                        $.ajax({
                            type: 'POST',
                            url: api+'login/oauth2',
                            data: {
                                avatar: avatar,
                                token: accessToken,
                            },
                            success: function (data) {
                              
                             
                            },
                            error: function (xhr, str) {
                                console.log(str);
                            }
                        });
                    
                });
            }
            else {
                FB.login(function (response) {
                    if (response.status === 'connected') {

                        var url = '/me?fields=name,email,picture.width(300).height(300)';
                        var userName, userEmail, accessToken, userID;
                        accessToken = response.authResponse.accessToken;
                        userID = response.authResponse.userID;

                        FB.api(url, function (response) {
                            userName = response.name;
                            userEmail = response.email;
                            avatar = response.picture.data.url;
                           
                                $.ajax({
                                    type: 'POST',
                                    url: api+'login/oauth2',
                                    data: {
                                        avatar: avatar,
                                        token: accessToken,
                                    },
                                    success: function (data) {
                        
                                    },
                                    error: function (xhr, str) {
                                        console.log(str);
                                    }
                                });
                            }

                        });//api FB
                    

                }, {scope: 'email'});
            }
        });
    };
    (function () {
        var e = document.createElement('script');
        e.async = true;
        e.src = document.location.protocol +
        '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
    }());
});
/*facebook oauth*/

请帮助,我的代码中有什么问题,因为浏览器阻止会弹出Facebook窗口。我不知道。在某些浏览器中它被阻止,有时候还可以。我应该找出解决方法。

0 个答案:

没有答案