I'm working on a facebook app that will allow users to login and will retrieve there photos. I've got Facebook Login to work with a redirect to get the access token, but I'd actually like to make my app a little bit better and use ajax to get the access token.
I'm using the Facebook JS SDK to login into my app. I'm using the Facebook PHP SDK for the rest of it, like retrieving user albums and photos.
I'm confused about getting the access code using ajax from the login.php page. I see that that page sets the access token and can return that value from this page.
My loginWithFacebook function looks like this:
// REQUIRED - using the facebook js to login
logInWithFacebook = function() {
FB.login(function(response) {
if (response.authResponse) {
// alert('You are logged in & cookie set!');
// Now you can redirect the user or do an AJAX request to
// a PHP script that grabs the signed request from the cookie.
// Redirect Way
window.location.href = 'app5.1.js-login.php';
} else {
alert('User cancelled login or did not fully authorize.');
}
}, {scope: 'public_profile,email,user_photos'}
);
return false;
};
As you can see I'm doing a redirect. I wanna change that part to pull in the access token with ajax, but I'm not exactly how to do that part and also how to keep it communicating with the rest of the app.