Here is my scenario. When a user opens a browser and goes to facebook to sign himself in, I want to be able to detect that and init my Facebook application sign-in process.
Is that possible? I'm asking because I noticed that signing into Facebook itself doesn't get my app signed in automatically, which is not good.
I'd prefer JavaScript client code.
Here is my scenario. When a user opens a browser and goes to facebook. to sign himself in, I want to be able to detect that and init my Facebook application sign-in process.
Is that possible? I'm asking because I noticed that signing into Facebook itself doesn't get my app signed in automatically, which is not good.
I'd prefer JavaScript client code.
Share Improve this question edited Apr 10, 2011 at 5:34 Michael Petrotta 61k27 gold badges152 silver badges181 bronze badges asked Apr 10, 2011 at 5:29 bootsboots 211 silver badge2 bronze badges 3- fbjs is the javascript API for FBML, which is deprecated in favor of the graph API. You can read about the new javascript SDK here: developers.facebook./docs/reference/javascript – Aleadam Commented Apr 10, 2011 at 5:47
- thanks for the answers, I've tried the above event based handling, but doesn't seem to work. i also read the javascript doc pointed out by Michael, the following paragraph is exciting but also confusing. "The Facebook JavaScript SDK allows you to remove user registration and sign-in by allowing the user to login to your site with their Facebook account. This is achieved by sharing the logged in user state between facebook. and your site. A Facebook user remains logged in to your site as long as they are logged in to Facebook." because based on my observation. sign int – user776635 Commented Apr 10, 2011 at 6:20
- by sharing the logged in user state is EXACTLY what you want, right? Besides a couple of mistakes on my example due to incorrect cutting and pasting (I was removing the non-relevant parts of an app of my own), the example was correct. Now those are fixed: I tested it and it works as expected. The example just reloads the page, but you can very well use an iframe instead. – Aleadam Commented Apr 10, 2011 at 7:04
3 Answers
Reset to default 5UPDATE: Here you have a FULLY WORKING example. The only thing you will need to do is to replace the APP_ID for whatever ID you get when sign your app at: http://www.facebook./developers/ and the port you may use for the localhost test. This detects when the user logs in even in another browser window. It is obviously extremely basic but proves the point that is feasible with the tools from the graph API.
You can add this code to detect when the user logs in. It is the same oauth log in whether the user clicks on a <fb:login-button>
or logs directly onto facebook.:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Hello App Engine</title>
<SCRIPT type="text/javascript" src="http://connect.facebook/en_US/all.js"></SCRIPT>
</head>
<body>
<h1>Hello!</h1>
<div id="fb-root"></div>
<script type="text/javascript">
FB.init({
appId : APP_ID,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
/*
* Authentication functions
*/
FB.Event.subscribe('auth.login', function (response) {
weleMsg(response);
});
FB.Event.subscribe('auth.logout', function (response) {
alert ("Good bye!");
});
if (FB.getSession() != null) {
FB.api('/me', function(response){
console.log(response.name);
weleMsg(response);
})
} else {
window.setTimeout(function(){window.location.href="http://localhost:8888"},5000);
}
function weleMsg(userData) {
console.log ("Wele " + userData.name);
}
</script>
</body>
</html>
You can subscribe to the auth.login event. http://developers.facebook./docs/reference/javascript/FB.Event.subscribe/
There are many Facebook images that you can see only if you're logged into Facebook. You can make the user attempt to load one of these images, and then detect if it loaded or not. It's a total trick.