Android的 - 使用ParseFacebookUtils.logIn Facebook时会议闭幕 [英] Android - Facebook session CLOSED when using ParseFacebookUtils.logIn

查看:222
本文介绍了Android的 - 使用ParseFacebookUtils.logIn Facebook时会议闭幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Andr​​oid应用程序中使用Facebook和解析SDK。我跟着教程Facebook登录和验证,片段之间改的登录片段主菜单片段取决于会话状态是否是开放 Session.StatusCallback 。和应用程序使用Parse整合之前完美的作品。

I am using Facebook and Parse SDK in my Android app. I followed this tutorial for Facebook login and authentication, changing between fragments for login fragment and main menu fragment depending on whether the session state is OPENED in the Session.StatusCallback. And the app works perfectly before integrating with Parse.

现在我遇到一个问题。在主菜单中片段的 onResume()方法,添加以下code。

And now I encounter a problem. In the onResume() method of the main menu fragment, I added the following code.

final Session session = Session.getActiveSession();

if(session != null && session.isOpened()) {
    Request meRequest = Request.newMeRequest(session, new Request.GraphUserCallback() {
    @Override
        public void onCompleted(GraphUser graphUser, Response response) {
            if(session == Session.getActiveSession()) {
                // Check if the session is same as usual 
                ParseFacebookUtils.logIn(graphUser.getId(), session.getAccessToken(), 
                        session.getExpirationDate(), new LogInCallback() {
                    @Override
                    public void done(ParseUser user, ParseException err) {
                        if (user == null) {
                            // The user wasn't saved.
                            System.out.println("User was not saved to Parse. ");
                        } else {
                            // The user has been saved to Parse.
                            System.out.println("User has successfully been saved to Parse.");
                            if (user.isNew()) {
                                // This user was created during this session with Facebook Login.                       
                                System.out.println("ParseUser created.");
                            } else {
                                // This user existed before.
                                System.out.println("User exists in Parse. Pull their values: " + user);
                            }
                        }
                    }
                });     
            }
        }
    });
    meRequest.executeAsync();
}

所以,当片段重新开始,Facebook的会话被打开,Facebook的用户将被添加到解析数据库,这样我可以使用 ParseUser GET 数据之后。但是,使用时会发生问题 ParseFacebookUtils.logIn(),这使得Facebook的会议并调用 Session.StatusCallback ,从而切换可见片段返回到登录片段。

So when the fragment is resumed and the Facebook session is opened, the Facebook user is added to the Parse database so that I can use ParseUser to put and get data afterwards. But the problem happens when using ParseFacebookUtils.logIn(), that it makes the Facebook session CLOSED and invokes the Session.StatusCallback, thus switching the visible fragment back to the login fragment.

我这个问题整天打交道,但无法找到一个解决方案。我曾经在应用程序增加了code以下,但仍然没有的工作。

I was dealing with this problem all day but cannot find a solution. I have added the code below in an Application but still not work.

Parse.enableLocalDatastore(this);
Parse.initialize(this, Application_id, Client_key);
ParseFacebookUtils.initialize(getString(R.string.facebook_app_id));

是有办法解决这一问题?我已阅读但是没有提供相当不错的解决方案。在此先感谢!

Is there a way to fix this? I have read this but no quite good solution is provided. Thanks in advance!

推荐答案

我是想今天做同样的事情。我使用Facebook SDK的UiLifecycleHelper做Facebook登录,使图形API请求,并添加用户解析分贝。这就是它是如何在你提到的例子做了 - 我认为这是一个有点过时

I was trying to do the same thing today. I was using the facebook sdk's UiLifecycleHelper to do the facebook login, make the graph api request and add the user to Parse db. That is how it is done in the example you mentioned - which I think is a bit outdated.

ParseFacebookUtils处理会话和所有我们需要做的是调用登录方法就可以了,使图形API调用,得到这样的电子邮件用户数据和更新用户领域。

ParseFacebookUtils handles the session and all we need to do is call the login method on it, make the graph api call, get user data like email and update the user field.

下面是一些code:

private void parseFacebookLogin(){
        ParseFacebookUtils.logIn(this, PARSE_FB_LOGIN_CODE, new LogInCallback() {
            @Override
            public void done(ParseUser user, ParseException err) {
                if (user == null) {
                    Log.d(tag, "Uh oh. The user cancelled the Facebook login.");
                } else if (user.isNew()) {
                    Log.d(tag, "User signed up and logged in through Facebook!");
                    Request.newMeRequest(ParseFacebookUtils.getSession(), graphUserCallback).executeAsync();
                } else {
                    Log.d(tag, "User logged in through Facebook!");
                }
            }
        });
    }

GraphUserCallback graphUserCallback = new GraphUserCallback() {
        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (user != null){
                getUserDataFacebook(user);
                Log.d(tag, response.toString());
            }
        }
    };

private void getUserDataFacebook(GraphUser user){
//get user data here
}

查看解析的文档在 Facebook登录

让我知道这对你的作品。

Let me know if this works for you.

这篇关于Android的 - 使用ParseFacebookUtils.logIn Facebook时会议闭幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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