使用解析Facebook登录api,导致当前用户为null [英] Using parses Facebook login api, results in current user null

查看:145
本文介绍了使用解析Facebook登录api,导致当前用户为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用解析来创建一个简单的演示网站,允许用户使用他们的Facebook帐户登录/注册。

I am using parse to crate a simple demo site that allows users to login/signup using their Facebook account.

登录返回成功,我也得到正确的用户name
i也看到数据库获得了facebook帐号数据

the login returns success, i also get correct user name i also see the database get populated with the facebook acount data

但是回到了app.js: Parse.User.current( ) null

but back at app.js: Parse.User.current() is null

客户端的Jvascript(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>


推荐答案

Parses会话处理似乎存在错误facebook。

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,

你可以使用会话成为,你获得的facebook令牌应该

you can use session become with the facebook token you acquired should do

诀窍

这篇关于使用解析Facebook登录api,导致当前用户为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆