1

我尝试将 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,而不是返回实例化的。详细地说,它返回这个:

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

0 回答 0