Reputation: 29
I am trying to retrieve Facebook user info on a web app hosted on Google App Engine.
The setup is: 1. web app hosted on the default appspot.com from Google. 2. Have a Facebook app is registered, and configured for "Website with Facebook Login".
I am using the FB JavaScript SDK to authenticate and retrieve data through the simple code below:
function login(){
FB.getLoginStatus(function(r) {
if(r.status === 'connected') {
FB.api('/me', function(user) {
alert(JSON.stringify(user));
});
}else{
FB.login(function(response) {
if(response.authResponse) {
alert("Now.... Thats better with FB!");
} else {
alert("You should connect to FB.");
}
});
}
});
};
But when I get the 'user' response back from the FB.api(...) call, its the following JSON:
{"error":{"type":"http", "message":"unknown error"}}
In my Facebook app, my "Site URL" in "Website with Facebook Login" section of Facebook App Settings is pointing to a https address of my GAE app. And I am not sure why such error shows.
I spent alot of time searching through StackOverflow and entire web but no reference to this. Could someone please...really please, help! :)
Thank you.
Upvotes: 1
Views: 805
Reputation: 29
After quite some investigation and try/errors, I found what the issue is :)
I was calling the login()
function from an onclick event as follows:
<a href='' onclick='login();'>
Now the Facebook login dialog called in my login() was not returning properly due to a issue (feature?) which was unknown to me till this date. That I need to add return false;
to the end of function call in onclick to make sure the browser performs its default behaviour of closing the opened window (of which FB.login depends on, to store proper access key). Therefore, since the window wasnt behaving properly, proper access key is not stored and found by FB.api, hence the call fails. Long story short, the fix was as easy as this:
<a href='' onclick='login();return false;'>
Hope this helps others.
Upvotes: 2