通过在Android应用设备的浏览器通过应用VS Facebook登录 [英] Facebook login via app VS via device browser in android app

查看:130
本文介绍了通过在Android应用设备的浏览器通过应用VS Facebook登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题一直缠着我了很多。在我的模拟器着,当然,也没有Facebook的应用程序有,所以当我触发它去我的浏览器打开的活动会话。现在,我测试了它的Facebook应用程序的设备上,它触发的应用程序,并要求进行登录。这里的问题出在哪里进来,在模拟器上或没有的Facebook应用程序的设备,它能够正确识别会话,使用这种code。

This problem's been bugging me a lot. On my emulator, ofcourse, there's no facebook app there so when I trigger the open active session it goes to my browser. Now, I tested it on a device with facebook app and it triggers the app and ask for a login. Here's where the problem comes in, on the emulator or a device without an facebook app, it recognizes the session correctly, using this code.

Session session = Session.getActiveSession();
    //check if user is logged in at facebook

    if (session != null && session.isOpened()) {
        Log.i("", "Session Open");
        Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

            // callback after Graph API response with user object
            @Override
            public void onCompleted(GraphUser user, Response response) {
              if (user != null) {
                  facebookId = user.getId();
                  loginType = 2;
                  LogMeIn();

              }
            }
          });
    } 
    else 
    {
        Log.i("", "Session Closed");
        // start Facebook Login
        Session.openActiveSession(this, true, new Session.StatusCallback() {

          // callback when session changes state
          @Override
          public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {
                Log.i("", "Session Open");
              // make request to the /me API
              Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                // callback after Graph API response with user object
                @Override
                public void onCompleted(GraphUser user, Response response) {
                  Log.i("", "Complete");
                  if (user != null) {
                      facebookId = user.getId();
                      loginType = 2;
                      LogMeIn();

                  }
                }
              });
            }
            else
            {
                Log.i("", "Session Closed");
            }
          }
        });
    }

但是,当在功能NEW应用程序的设备,会话始终为空。所以趋势是再次火起来的Session.openActiveSession和我总是最后得到一个会议闭幕每当我检查一下。上有什么问题的任何想法家伙?是我的方法错了,这就是为什么它只能通过浏览器对Facebook登录行之有效?任何帮助将满AP preciated。谢谢!

But when in a device that has a faceboook app, the session is always null. So the tendency is to fire up again the Session.openActiveSession and I always end up getting a session closed whenever I check it. Any ideas guys on what's the problem? Is my approach wrong that's why it only works well on facebook login via browser? Any help will be full appreciated. Thanks!

推荐答案

你能够在Facebook的SDK会话跟踪?您需要创建一个 UiLifecycleHelper 活动的onCreate()

Did you enable session tracking in the Facebook SDK? You need to create a UiLifecycleHelper in your Activity's onCreate():

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = new UiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);
}

这是传递到构造函数的回调是(你做到了匿名)你在上面code创建的那个。

The callback which is passed into the constructor is the same one you created in your above code (you did it anonymously).

在这之后你需要匹配你的活动调用的生命周期方法的 UiLifecycleHelper >。这将允许Facebook的SDK来追踪您的会话。

After this you need to make matching calls in your Activity's lifecycle methods to the same ones of the UiLifecycleHelper. This will allow the Facebook SDK to track your session.

@Override
public void onResume() {
    super.onResume();
    uiHelper.onResume();
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
public void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

您可以在这里找到在更多的细节他们的教程。你可能跟着他们简单的入门的教程,而不是更深入的登录之一。无论用户是通过应用程序登录(因为它的安装),或浏览器应该不会影响会话跟踪,如果你有它设置正确。

You can find more details here in their tutorial. You probably followed their simpler "Getting Started" tutorial instead of the more indepth "Login" one. Whether or not the user is logging in through the app (because it's installed) or the browser shouldn't affect the session tracking if you have it set up properly.

这篇关于通过在Android应用设备的浏览器通过应用VS Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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