tangteng78
asked on
How to login using FB api and redirect to next page?
Hi,
I'm able to login to FB using the FB api, but to redirect to the next page (logged in page), i need to click refresh.
Is there anything that i missed out? Any help is greatly appreciated.
I'm able to login to FB using the FB api, but to redirect to the next page (logged in page), i need to click refresh.
Is there anything that i missed out? Any help is greatly appreciated.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>muncch</title>
<script src="http://connect.facebook.net/en_US/all.js">
</script>
<script>
function bodyload()
{
FB.init({
appId: '123455667', cookie: true,
status: true, xfbml: true
});
FB.api('/me', function (user) {
if (user.id != null) {
var image = document.getElementById('image');
image.src = 'http://graph.facebook.com/' + user.id + '/picture';
var name = document.getElementById('name');
name.innerHTML = user.name
var txtUserID = document.getElementById('txtUserID');
txtUserID.value = user.id;
//With user login, now redirect user to new page
window.location = "http://www.xxx.com/icanadd/json.aspx"
//alert('im logged on');
}
else {
alert('im nothing');
}
});
}
</script>
</head>
<body onload="bodyload();">
<form id="form1" runat="server">
<div id="fb-root"></div>
<a href="https://www.facebook.com/dialog/oauth?client_id=123456&redirect_uri=http://www.xxx.com/icanadd/json.aspx">click to login</a>
</form>
</body>
</html>
http://stackoverflow.com/questions/3548493/how-to-detect-when-facebooks-fb-init-is-complete
fbEnsureInit(function() {
location.href = "http://www.xxx.com/icanadd/json.aspx";
});
ASKER
Okay, now it's able to redirect to json.aspx, great.
But the same issue exist on this page(json.aspx), even though i'm redirected to the page, i still need to click refresh for me to be able to access the fb logged in cookie.
But the same issue exist on this page(json.aspx), even though i'm redirected to the page, i still need to click refresh for me to be able to access the fb logged in cookie.
ASKER
Any help is appreciated guys. Thanks.
What about :
or :
FB.Event.subscribe("auth.logout", function(response) {
alert("You loggout");
});
or :
FB.Event.subscribe("auth.login", function(response) {
t = setInterval(FB.getLoginStatus(function(response) { if(response.session && response.status != "connected") { clearInterval(t) } }), 1500);
alert("You're logged");
});
ASKER
Doesn't work.
After logged in and redirect to the json.aspx page, i still need to refresh (hit F5) before i'm able to get the FB cookie so that i can extract the Graph API.
Is there an example out there that shows the whole nine yards from authentication to logged in page??
After logged in and redirect to the json.aspx page, i still need to refresh (hit F5) before i'm able to get the FB cookie so that i can extract the Graph API.
Is there an example out there that shows the whole nine yards from authentication to logged in page??
The first one take its time but it work
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.