2014-10-31 2 views
0

我是新來的android。我正在開發一個需要Facebook登錄的應用程序。因此,對於這個我按照這個教程 - https://developers.facebook.com/docs/android/getting-started通過Android應用程序的Facebook身份驗證

編輯:使用UILifecycleHelper,同樣的事情發生,一旦用戶通過驗證的應用程序被關閉。

private Session.StatusCallback callback = new Session.StatusCallback() { 
     @Override 
     public void call(Session session, SessionState state, Exception exception) { 
      if (session.isOpened()) { 
       Log.w("Vinit", "Session started"); 
       // make request to the /me API 
       Request.newMeRequest(session, new Request.GraphUserCallback() { 

       // callback after Graph API response with user object 
       @Override 
       public void onCompleted(GraphUser user, Response response) { 
        if (user != null) { 
        TextView t = (TextView) findViewById(R.id.textView1); 
        t.setText("User: " + user.getFirstName()); 

        } 
       } 
       }).executeAsync(); 
      } 
     } 
    }; 

    private FacebookDialog.Callback dialogCallback = new FacebookDialog.Callback() { 
     @Override 
     public void onError(FacebookDialog.PendingCall pendingCall, Exception error, Bundle data) { 
      Log.d("HelloFacebook", String.format("Error: %s", error.toString())); 
     } 

     @Override 
     public void onComplete(FacebookDialog.PendingCall pendingCall, Bundle data) { 
      Log.d("HelloFacebook", "Success!"); 
     } 
    }; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     // TODO Auto-generated method stub 
     super.onCreate(savedInstanceState);    
     if(new LoginChecker(this).isRegistered()){ 
      Intent intent = new Intent(this, MainActivity.class); 
      startActivity(intent); 
     }else{ 
      setContentView(R.layout.activity_login);    
      LoginButton loginButton = (LoginButton) findViewById(R.id.loginButton1); 
      thisActivity = this; 
      loginButton.setOnClickListener(new OnClickListener() {        
       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub     
        uiHelper = new UiLifecycleHelper(thisActivity, callback); 
       } 
      }); 

     } 
    } 
    @Override 
    public void onActivityResult(int requestCode, int resultCode, Intent data) { 
      super.onActivityResult(requestCode, resultCode, data); 
      Log.w("Vinit", "On Activity Result function"); 
      uiHelper.onActivityResult(requestCode, resultCode, data, dialogCallback); 
    } 
+0

它調用'onActivityResult'嗎? – Pr38y 2014-10-31 12:41:48

+0

沒有它沒有調用onActivityResult – codeomnitrix 2014-10-31 13:03:38

+0

你的'會議'已經創建?檢查 'Session session = Session.getActiveSession(); \t \t如果(會話== NULL){ \t \t //嘗試從緩存中恢復 \t \t會話= Session.openActiveSessionFromCache(mActivity); \t \t}' – Pr38y 2014-10-31 13:35:17

回答

1
  1. 使用UiLifecycleHelper https://developers.facebook.com/docs/reference/android/current/class/UiLifecycleHelper ,以確保在適當的方式Facebook的組件的活動/片段手柄處理。
  2. 檢查Facebook Session對象。 應用程序在session.IsOpened()內調用指令嗎?嘗試調試您的代碼以查看Facebook Session的狀態。
+0

嗨夥伴,它永遠不會進入Session.isOpened()代碼。我已經放置了一個斷點,但永遠不會去那裏。此外,我還放置了log.d(),但logcat上也沒有提供。 – codeomnitrix 2014-10-31 13:13:27

+0

你用UiLifecycleHelper試過了嗎?你有沒有正確的AndroidManifest?仔細閱讀https://developers.facebook.com/docs/android/scrumptious/authenticate – mklimek 2014-10-31 13:24:31

+0

嗨,我已經使用UILifeCycleHelper,但結果相同,請參閱更新的代碼,我會參考您發佈的其他鏈接。謝謝 – codeomnitrix 2014-10-31 13:35:22

相關問題