问题描述
当前使用PHP与Facebook api建立连接,在facebook开发人员中创建一个项目,生成相应的密钥,至于我使用默认用户名和邮件许可权,允许我输入和授予该应用程序许可,但有时并不能带来所有用户信息,有时当您单击按钮facebook时,无法打开弹出窗口以使用facebook登录或使用我的帐户授予该应用程序许可,有时,如果没有,我不会知道为什么并且情况还是很断断续续的,在浏览器控制台中并没有告诉我这是由于间歇性造成的,值得一提的是,如果有大量的人试图在Facebook上使用登录名,那间歇性无法登录,我在html正文之前有此脚本:
window.fbAsyncInit = function () {
FB.init({
appId: '<?PHP echo $UrlApiFacebook; ?>',cookie: true,// Enable cookies to allow the server to access the session.
autoLogAppEvents : true,xfbml: true,// Parse social plugins on this webpage.
version: 'v7.0' // Use this Graph API version for this call.
});
};
(function(d,s,id) { // Load the SDK asynchronously
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'));
function checkLoginState() {
FB.getLoginStatus(function (response) { // Called after the JS SDK has been initialized.
statusChangeCallback(response,1); // Returns the login status.
});
}
对于此代码,我直接依赖于Facebook开发人员的官方文档,在另一个javascript文件中,函数“ statusChangeCallback()”的内容如下所示:
function statusChangeCallback(response,i) {
console.log('statusChangeCallback');
console.log(response);
if (i == 3) {
if (response.status === 'connected') { // Logged into your webpage and Facebook.
FB.logout(function (response) {
window.location.href = "login_out.PHP";
});
} else {
window.location.href = "login_out.PHP";
}
} else {
if (response.status === 'connected') { // Logged into your webpage and Facebook.
testAPI();
} else { // Not logged into your webpage or we are unable to tell.
console.log("No logueado");
FB.login(function (response) {
if (response.status === 'connected')
testAPI();
});
}
}
}
function testAPI() { // Testing Graph API after login. See statusChangeCallback() for when this call is made.
console.log('Welcome! Fetching your @R_444_4045@ion.... ');
FB.api('/me',{ fields : 'name,picture,first_name,last_name,email' },function (response) {
console.log('Successful login for: ' + response.name);
onSendDataFacebook(response);
});
}
function logoutUserFacebook() {
FB.getLoginStatus(function (response) { // Called after the JS SDK has been initialized.
statusChangeCallback(response,3); // Returns the login status.
});
}
function onSendDataFacebook(userFacebook) {
let email = "";
let name = "";
let last_name = "";
var user = {
id: userFacebook.id,nombre: userFacebook.name,email: userFacebook.email,nombrecompleto: userFacebook.first_name + ' ' + userFacebook.last_name,llamado: redir,veces: x
}
if(!userFacebook.email){
user.email = email;
}
if(!userFacebook.name){
user.name = name;
}
if(!userFacebook.first_name || !userFacebook.last_name){
user.first_name = name;
user.last_name = last_name;
}
redireclogin(user);
}
非常感谢任何了解这次间歇活动的人的帮助,在此先感谢您。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)