Facebook Graph API:调用FB.init()前调用FB.login() [英] Facebook Graph API: FB.login() called before calling FB.init()
本文介绍了Facebook Graph API:调用FB.init()前调用FB.login()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
页面上的某个地方:
< fb:login-button autologoutlink =trueperms =email,user_birthday,status_update,publish_stream>< / fb:login-button>
标签后:
< div id =fb-root>
< / div>
< script type =text / javascript>
window.fbAsyncInit = function(){
FB.init({appId:'<%= ConfigurationManager.AppSettings [FBAppId]%>',status:true,cookie:true,xfbml :true});
/ *所有注册的事件* /
FB.Event.subscribe('auth.login',function(response){
// do something with response
alert(login success);
});
FB.Event.subscribe('auth.logout',function(response){
// do something with response
alert(logout success);
});
FB.getLoginStatus(function(response){
if(response.session){
//登录和连接的用户,你认识的人
alert(登录成功);
}
});
};
(function(){
var e = document.createElement('script');
e.type ='text / javascript';
e.src = document.location .protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root')。appendChild( e);
}());
< / script>
但是当我点击生成的登录按钮时,没有任何反应。
此外,我正在获得
FB.getLoginStatus()在调用FB.init()之前调用。
在Firebug控制台。
任何想法?
解决方案
我不敢相信,我在Web.config中引用了一个非现有的密钥,因此FB.init是
它的工作原理如下。
要更清楚没有将appId传递给FB.init,一旦我这样做,它就可以工作。
I'm trying to use the new Facebook Graph API on my website. This is what I have:
Somewhere on the page:
<fb:login-button autologoutlink="true" perms="email,user_birthday,status_update,publish_stream"></fb:login-button>
Right after the tag:
<div id="fb-root">
</div>
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({ appId: '<%= ConfigurationManager.AppSettings["FBAppId"] %>', status: true, cookie: true, xfbml: true });
/* All the events registered */
FB.Event.subscribe('auth.login', function (response) {
// do something with response
alert("login success");
});
FB.Event.subscribe('auth.logout', function (response) {
// do something with response
alert("logout success");
});
FB.getLoginStatus(function (response) {
if (response.session) {
// logged in and connected user, someone you know
alert("login success");
}
});
};
(function () {
var e = document.createElement('script');
e.type = 'text/javascript';
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
} ());
</script>
but when I click on the generated login button, nothing happens.
In addition, I'm getting
FB.getLoginStatus() called before calling FB.init().
in Firebug console.
Any ideas?
解决方案
I can't believe it, I was referencing a non existing key in the Web.config hence FB.init was failing silently.
It works as expected now.
To be clearer I wasn't passing the appId to FB.init, once I did, it worked.
这篇关于Facebook Graph API:调用FB.init()前调用FB.login()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文