facebook comments callback function - facebook

I'm trying to fire an event when you log in to comment, but for some reason the event doesn't fire. Here's my code:
<script src="http://connect.facebook.net/en_US/all.js#appId=158693604164389&xfbml=1"></script>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({ appId: '158693604164389', status: true, cookie: true, xfbml: true });
FB.Event.subscribe('auth.login', function(response) {
document.getElementById('newsletter-placeholder').style.display = "block";
});
};
</script>
Any idea?
Thanks in advance.
Mauro

I suppose you mean, when the user logs-in when trying to use the comments plugin?
If this is what you mean, then no you can't capture this event!
auth.login -- fired when the user logs
in
This is fired when the user logs in (connects) to your application!

Related

facebook Log In Button

I'm implementing facebook authentication (register + login) at my website. Everything works fine, except for the button showing even if I'm logged in. Thanks in advance
<h1 id="welcome">Welcome to my website</h1>
<div id="fb-root"></div>
<span id="fb-login" class="hidden">
<fb:login-button registration-url="http://lemiart.com/register.php"></fb:login-button>
</span>
<script src="https://connect.facebook.net/en_US/all.js#appId=306738122732711&xfbml=1"></script>
<script type="text/javascript">
FB.init({appId: '306738122732711', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.login', function(){
loggedIn();
});
FB.getLoginStatus(function(response){
if (response.session){
// user logged in. Let the auth.login subscription handle this
} else {
loggedOut();
}
});
loggedIn = function() {
FB.api('/me', function(response) {
var welcome = document.getElementById('welcome');
if (welcome) welcome.innerHTML += ' ' + response.id;
document.getElementById('fb-login').className = "hidden";
})
}
loggedOut = function() {
document.getElementById('fb-login').className="";
}
</script>
Your current implementation will always prompt the user to login. What you perhaps need to do is the following:
write a callback function to FB.init, which then checks if the user is logged into your application and then decide if you want to show the fb:login-button.
It would look something like this:
window.fbAsyncInit = function() {
FB.init({
//...
});
FB.getLoginStatus(function(response){
FB.getLoginStatus(function(response){
if (response.session){
// user logged in. Let the auth.login subscription handle this
} else {
loggedOut();
}
});
};

FB.Event.subscribe('auth.logout', function(response) and redirect to site not working

We are using
<fb:login-button autologoutlink="true"></fb:login-button>
and for logout:
FB.Event.subscribe('auth.logout', function(response)
But after clicking on logout button it logs out from facebook, but does not reload the page and FB.Event.subscribe('auth.logout', function(response) does not work
Have you made sure that you are doing the FB.Event.subscribe inside the window.fbAsyncInit function? For example:
window.fbAsyncInit = function() {
FB.init({
......
)};
FB.Event.subscribe('auth.logout', function(response){
// User is now logged out
window.refresh();
)};
};
I had a similar problem, and when I had the Event.subscribe outside of the fbAsyncInit it would not fire, but moving it inside fixed the problem. Hopefully this works for you.

Calling the Facebook API

I has developed my apps and now I want to integrate them into Facebook. But I realize that it is dificult. I have this init method:
<javascript>
FB.init({
appId : '123456789',
status : true,
cookie : true,
xfbml : true,
channelUrl : 'http://xyz.dyndns.org:8080/fbchannel.html',
oauth : true
});
</javascript>
After that, I can call FB.login, and FB.ui to prompt to get permission, it's OK. But if I want to get some information with FB.api() (for example, get the user name, etc.), it doesn't work. How do I call the API?
The problem is: I can call fb.init. fb.login, fb.ui, and fb.getLoginStatus, but I can't call fb.api, not even the simplest method.
In my application setting, I used an application in Facebook, and then I typed my URL (a web application), htt://xyz.dyndns.org:8080/... . Is it OK?
(I am a newcomer in making applications in Facebook.)
What error are you getting? Here is a working FB.api call example:
<!DOCTYPE html>
<html>
<body>
<div id="fb-root"></div>
Get Info
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({ appId: '**appId**', status: true, cookie: true, xfbml : true });
function getInfo() {
FB.login(function(response) {
if (response.session) {
FB.api('/me', function(response) {
alert('User: ' + response.name);
});
}
});
return false;
}
</script>
</body>
</html>

Making client side authorization to Facebook using Javascript JQuery

Here is what I want to:
I used OAuth 2.0 authorization system.
I already registered my application in Facebook, and I have got my application secret keys (i did server side code, but I need more user friendy authorization system).
Based on response from Facebook, how can I get response code from Facebook without reloading the page? In case you didn't understand what I mean take a look on next example:
Example is on this link:
http://www.badminton.si/1-turnir-b-kategorije-1-kolo-mbl
How can I then continue to get my access token so I can access my private information (like email)?
IN SHORT:
<script type="text/javascript" src="../Scripts/jquery-1.4.1-vsdoc.js"></script>
<script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript" src="http://static.ak.fbcdn.net/connect/en_US/core.debug.js"> </script>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
FB.init({
appId: my_api_key,
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.login', function (response) {login();)}
FB.Event.subscribe('auth.logout', function (response) {logout();});
FB.getLoginStatus(function (response) {if (response.session) {login();}});
function login() {FB.api('/me', function (response) {alert(response.email)});
....
<fb:login-button v="2" size="large" autologoutlink="true" perms="email,user_birthday,status_update,publish_stream,read_stream">
</fb:login-button>
Just follow the examples on http://developers.facebook.com/docs/authentication/
On most of the functions you'll get callbacks that you can catch to get a token without having to reload the page.
From the documentation:
FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('auth.sessionChange', function(response) {
if (response.session) {
// A user has logged in, and a new cookie has been saved
} else {
// The user has logged out, and the cookie has been cleared
}
});
With the response.session object you should get everything you need without having to reload the page.

Facebook Graph API: FB.login() called before calling 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.
Had the same issue, here is the solution that worked for me. Just put the following in your head section or in other words, add the app_id to the source of the facebook js.
<script src="//connect.facebook.net/en_US/all.js&appId=xxxxxxxxxxxxxxx" type="text/javascript"></script>
In my case, the problem went away after I disabled the XFBML functionality (i.e. setting the xfbml key to false, removing the fb: namespace and the #xfbml=1 fragment in <script src="…">). Good that I didn’t need it anyway.
YMMV, there are several other valid reasons why this error message can appear.