Facebook的API:在Android上无法登陆 [英] Facebook API: cannot login on Android

查看:172
本文介绍了Facebook的API:在Android上无法登陆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android上导入Facebook登录,使用Facebook的API。我所做的一切说的方式 Facebook的登录流程。在code如下。

I'm trying to implement Facebook login on Android, using the Facebook API. I've done everything the way Facebook Login Flow says. The code is below.

public class FBSignIn extends Fragment {
    private UiLifecycleHelper uiHelper;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        final View v = super.onCreateView(inflater, container, savedInstanceState);
        setTitle("Sign In");
        reloadTemplate();

        uiHelper = new UiLifecycleHelper(getActivity(), callback);
        uiHelper.onCreate(savedInstanceState);

        return v;
    }

    @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);
    }

    @Override
    public boolean executeCommand(BaseWebView webView, String command, String data) {

        if (command.equalsIgnoreCase("login")) {
            Session session = Session.getActiveSession();

            if (session != null && session.isOpened()) {
                loginWithFBToken(session.getAccessToken());
                return;
            }

            Session.openActiveSession(getActivity(), true, callback);
        }

        return true;
    }

    private Session.StatusCallback callback = new Session.StatusCallback() {
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            onSessionStateChange(session, state, exception);
        }
    };

    private void onSessionStateChange(Session session, SessionState state, Exception exception) {
        if (state.isOpened()) {
            // Facebook logged in...

        } else if (state.isClosed()) {
            //Facebook logged out...
        }
    }

}

但是, Session.openActiveSession()调用,在 onSessionsStateChange()功能后,我第一次得到状态== CLOSED_LOGIN_FAILED ;这就是所谓的第二次,用后状态==开幕。因此,它永远不会成为一个开放状态。

However, after the Session.openActiveSession() call, in onSessionsStateChange() function, I first get state == CLOSED_LOGIN_FAILED; after that it's called the second time, with state == OPENING. So it never gets into an OPENED state.

有什么不对的code?我倒是很AP preciate你的帮助。

What's wrong with this code? I'd very much appreciate your help.

P.S。我注释掉有关的一切 uiHelper ,在我的主要活动,提供的覆盖方法:

P.S. I've commented out everything concerning uiHelper and, in my main activity, supplied the overriden method:

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

现在到 onSessionStateChange 第一次调用带有状态==开幕例外= = NULL 。第二个电话打进来与状态== CLOSED_LOGIN_FAILED 例外==无效的访问令牌。这是什么意思?

Now the first call to onSessionStateChange comes with state == OPENING and exception == null. The 2nd call comes with state == CLOSED_LOGIN_FAILED and exception == Invalid access token. What does that mean?

推荐答案

我已经解决了这个问题。其原因是,我们的应用程序是注册在Facebook在沙盒模式,只有特定的用户可以与Facebook登录。当我登录其中一个帐户下,它的工作。

I've solved the issue. The reason was that our app was registered in Facebook in Sandbox mode, and only certain users could log in with Facebook. When I logged in under one of these accounts, it worked.

这篇关于Facebook的API:在Android上无法登陆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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