我正在尝试使用facebook auth进行简单的反应网络应用程序登录,并使用npmjs包中的react-facebook-login进行授权,但它总是被弹出窗口拦截器阻止。因此我的代码是:
static defaultProps = {
textButton: 'Login with Facebook',
scope: 'public_profile, email',
xfbml: false,
cookie: false,
size: 'metro',
fields: 'name',
cssClass: 'kep-login-facebook',
version: '2.3',
language: 'en_US',
uri: encodeURI('http://myapps.com');
};
document.body.appendChild(fbRoot);
window.fbAsyncInit = () => {
FB.init({
appId: this.props.appId,
xfbml: this.props.xfbml,
cookie: this.props.cookie,
version: 'v' + this.props.version,
});
if (this.props.autoLoad) {
FB.getLoginStatus(this.checkLoginState);
}
};
((d, s, id) => {
const element = d.getElementsByTagName(s)[0];
const fjs = element;
let js = element;
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = '//connect.facebook.net/' + this.props.language + '/all.js';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}
responseApi = (authResponse) => {
FB.api('/me', { fields: this.props.fields }, (me) => {
Object.assign(me, authResponse)
this.props.callback(me);
});
};
checkLoginState = (response) => {
if (response.authResponse) {
this.responseApi(response.authResponse);
} else {
if (this.props.callback) {
this.props.callback({ status: response.status });
}
}
};
click = () => {
FB.login(this.checkLoginState, { scope: this.props.scope });
};
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>