I have a registration form that uses an old version of the FB API.
I am trying to update it to the current version and am having problems dealing with the response from FB.
After clicking the FB login button and granting permissions (email,publish_stream) I cannot find a way to know that the user has granted access (and not just logged in as an already registered user) and needs to proceed to the next page of the registration form.
The response after a successful permission request is the same as a successful login:
{
authResponse:
{
accessToken: AAAFEIew...URYo,
userID: 100003908595992,
expiresIn: 6014,
signedRequest: uhTqZodDn0QUoWAUBuYEKmlaM8zViO0r_fnKONaC4v8.eyJhbGdvcml...k5MiJ9,
},
status: connected
}
How can I tell if the login was the result of an already registered user or a new registration?
I am using the javascript SDK.
Code:
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<div id="fb-root" style="padding: 0px;"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'API_KEY',
status : true,
channelUrl : '//'+window.location.hostname+'/channel.php',
cookie : true,
xfbml : true,
oauth : true
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
alert('logged in!');
}
else
{
// user has not auth'd your app, or is not logged into Facebook
alert('not logged in!');
}
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
I realized that I needed to use the getLoginStatus function in the FB SDK.
My functioning code is: