Android的Facebook的SDK3.0,会话状态开幕 [英] Android Facebook SDK3.0, session state OPENING

查看:114
本文介绍了Android的Facebook的SDK3.0,会话状态开幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Facebook SDK 3.0检索按钮preSS的访问令牌在我的Andr​​oid应用程序。我在我的活动,目的是做如下的通用按钮:

I am trying to use the Facebook SDK 3.0 to retrieve an access token on button press in my android app. I have a generic button in my Activity that is doing the following:

Button facebook = (Button)findViewById(R.id.facebookLoginButton);
    facebook.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Session session = new Session(getApplicationContext());
            Session.setActiveSession(session);
            session.openForRead(new Session.OpenRequest(SignInActivity.this).setCallback(statusCallback));
        }
    });

然后回调:

private class FacebookSessionStatusCallback implements Session.StatusCallback {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
            String s=session.getAccessToken();
    }
}

点击该按钮会提示我要我的权限来访问我的个人资料如预期,但这种回调只会被调用一次,SessionState会为打开。后的状态,这并不改变。

Clicking the button prompts me for my permission to access my profile as expected, but this callback is only ever called once with SessionState as "OPENING". The state doesn't change after this.

我在想什么吗?我的最终目标是真的只是为了获得一个访问令牌一次,我真的不关心持续会话或使用它登录到我的应用程序。

What am I missing here? My end goal is really just to get an access token once, and I don't really care about persisting the session or using it to log into my app.

推荐答案

您需要重写onActivityResult这样经过凭据核对的Facebook为Android(或内联登录)的结果进行处理,并在会议上进行更新。添加以下code:

You need to override the onActivityResult so that after the credentials are checked against Facebook for Android (or an inline login) the results are handled and the session updated. Add the following code:

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

这篇关于Android的Facebook的SDK3.0,会话状态开幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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