Facebook Android sdk 3.0:活动结果的会话为空

时间:2013-05-10 11:35:17

标签: android facebook webview facebook-android-sdk

我尝试将Facebook Android sdk从2.0升级到3.0,但我遇到了一个问题,这是我的情况:

我有一个webview,当用户点击“Facebook登录”时,我会执行以下代码:

SharedPreferences mPrefs = act.getPreferences(Context.MODE_PRIVATE);
String access_token =  mPrefs.getString("access_token", null);
session = Session.getActiveSession();
if (session == null){
     session = new Session(act.getApplicationContext());
     if(access_token != null){
          SharedPreferences.Editor editor = mPrefs.edit();
      editor.putString("access_token", null);
      editor.commit();
      AccessToken accessToken = AccessToken.createFromExistingAccessToken(access_token,null, null, null, null);
          session.open(accessToken, callback);
      Session.setActiveSession(session);
     }
}
Session.OpenRequest request = new Session.OpenRequest(act);
String[] permissions = {"email, user_likes, user_checkins, publish_checkins, publish_stream"};
request.setPermissions(Arrays.asList(permissions));
request.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);
request.setCallback(callback);
session.openForPublish(request);

并在同一个类(扩展Activity)上,我得到了这段代码:

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

当用户点击按钮时,一切正常:facebook对话框打开,需要权限,对话框关闭。 问题是Session.getActiveSession()返回null,而不是返回instanciated。详细说明,它会返回:

{who=null, request=64206, result=-1, data=Intent { (has extras) }}

0 个答案:

没有答案