我正在使用Facebook登录..但最近我在获取用于登录/注册的数据时遇到错误
这是我的代码
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') {
// Logged into your app and Facebook.
testAPI();
} else if (response.status === 'not_authorized') {
fbLogin();
// The person is not logged into your app or we are unable to tell.
document.getElementById('status').innerHTML = 'Please log ' +'into this app.';
}
else {
// The person is not logged into your app or we are unable to tell.
document.getElementById('status').innerHTML = 'Please log ' +'into this app.';
}
}
function checkLoginState() {
FB.getLoginStatus(function (response) {
statusChangeCallback(response);
});
}
function fbLogin() {
debugger;
FB.login(function (response) {
//if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me/?fields=picture,name,email', function (response) {
console.log(response);
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
//} else {
// console.log('User cancelled login or did not fully authorize.');
//}
}, { auth_type: 'reauthenticate', auth_nonce: '{random-nonce}' });
}
window.fbAsyncInit = function () {
FB.init({
appId: '393788184007786',
cookie: true, // enable cookies to allow the server to access
// the session
xfbml: true, // parse social plugins on this page
version: 'v3.2' // The Graph API version to use for the call
});
};
// Load the SDK asynchronously
(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 = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', { fields: 'name,email' }, function (response) {
var info = response.id + '#' + response.name + '#' + response.email;
console.log('Successful login for: ' + info);
});
}
</script>
这是html中包含的用于登录的按钮
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
,来自getLoginState()的响应是:
{ authResponse: undefined, status: "not_authorized" }
这是显示错误enter image description here
我在Facebook应用程序中收到一条消息,内容为“我们已限制该应用程序违反Facebook平台政策”
有什么解决这个问题的建议吗?!
答案 0 :(得分:0)
括号只是占位符,您必须将其删除:
FB.init({
appId: '393788184007786',
cookie: true,
xfbml: true,
version: 'v3.2'
});