问题
I am using parse to crate a simple demo site that allows users to login/signup using their Facebook account.
the login returns success, i also get correct user name i also see the database get populated with the facebook acount data
but back at app.js: Parse.User.current()
is null
Jvascript on client side (index.html)
<script>
// Initialize Parse
Parse.initialize("zzzzzzzzzzzzzzzzzzzzz", "zzzzzzzzzzzzzzzzzzzzzzzz");
window.fbAsyncInit = function() {
Parse.FacebookUtils.init({ // this line replaces FB.init({
appId : 'zzzzzzzzzzzzzzz', // Facebook App ID
status : true, // check Facebook Login status
cookie : true, // enable cookies to allow Parse to access the session
xfbml : true, // initialize Facebook social plugins on the page
version : 'v2.3' // point to the latest Facebook Graph API version
});
// Run code after the Facebook SDK is loaded.
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function myFacebookLogin() {
Parse.FacebookUtils.logIn('user_friends', {
success: function(user) {
if (!user.existed()) {
alert("User signed up and logged in through Facebook!");
} else {
alert("Already logged on");
}
console.log(user);
alert("user "+user);
FB.api('/me', function(response)
{
$("#userIdInput").val(user.id);
$("#userNameInput").val(response.name);
$("#fb-login-form").submit();
});
},
error: function(user, error) {
alert("User cancelled the Facebook login or did not fully authorize.");
}
});
}
$( document ).ready(function() {
$("#logon-block").click(function(){
myFacebookLogin();
});
});
</script>
回答1:
There seems to be a bug with Parses session handling with facebook.
It might not be a solution, but it is a workaround for the meantime,
you can use session become
with the facebook token you acquired should do
the trick
来源:https://stackoverflow.com/questions/31766107/using-parses-facebook-login-api-results-in-current-user-null