2014-02-20 68 views
0

你好,我試圖使用Facebook登錄。沒有Session.StatusCallback收到

我的問題是,我沒有得到回電。

這裏是我的代碼:

private void onClickLogin() { 

     Session currentSession = Session.getActiveSession(); 
     if (currentSession == null || currentSession.getState().isClosed()) { 
      Session session = new Session.Builder(this).build(); 
      Session.setActiveSession(session); 
      currentSession = session; 
     } 

     // Ask for username and password 
     OpenRequest op = new Session.OpenRequest((Activity) this); 

     op.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO); 
     op.setCallback(null); 

     List<String> permissions = new ArrayList<String>(); 
     // permissions.add("publish_actions"); 
     permissions.add("user_photos"); 
     permissions.add("friends_photos"); 
     permissions.add("read_stream"); 
     permissions.add("read_insights"); 
     permissions.add("read_friendlists"); 
     permissions.add("email"); 
     permissions.add("publish_actions"); 

     op.setPermissions(permissions); 

     Session session = new Session.Builder(this).build(); 
     Session.setActiveSession(session); 
     session.openForPublish(op); 
    } 


@Override 
    protected void onActivityResult(int requestCode, int resultCode, 
      Intent data2) { 

     Session.getActiveSession().onActivityResult(RegisterPage.this, requestCode, resultCode, data2); 


    } 

rivate class SessionStatusCallback implements Session.StatusCallback { 

     @SuppressWarnings("deprecation") 
     @Override 
     public void call(final Session session, SessionState state, 
       Exception exception) { 

      Log.i("test", "test"); 
} 

}

回答

0

你需要註冊你的回調。你應該這樣做

private Session.StatusCallback statusCallback = new SessionStatusCallback();

.....

註冊我的OnStart方法

Session.getActiveSession()的addCallback(statusCallback)回調。

和予刪除它在的onStop方法

Session.getActiveSession()removeCallback(statusCallback)。

問候

邁克爾