2012-05-07 44 views
1

我已經做了一個程序,其中是Facebook的登錄按鈕,加載Facebook登錄頁面,但是即時控制返回到相同。窗口包括登錄按鈕... 同樣的程序在模擬器上執行得很好。Android:Facebook登錄

+0

你是否有Facebook應用程序安裝在你的設備..... – AndroidDev

回答

1

請看Facebook開發者API文檔。

問題是Anshuman說,你已經在你的手機上SSO,並試圖再次驗證中存在的問題的結果,你需要重寫onActivityResult,並做了特殊Facebook的authorizeCallback功能:

它是這樣的:

  facebook.authorize(SinglePost.this, permissions, 
       new DialogListener() { 

        @Override 
        public void onComplete(Bundle values) { 
         // control comes here if the login was successful 
         // Facebook.TOKEN is the key by which the value of 
         // access token is stored in the Bundle called 
         // 'values' 
         Log.d("COMPLETE", "AUTH COMPLETE. VALUES: " 
           + values.size()); 
         Log.d("AUTH TOKEN", 
           "== " + values.getString(Facebook.TOKEN)); 
         updateStatus(values.getString(Facebook.TOKEN)); 
        } 

        @Override 
        public void onFacebookError(FacebookError e) { 
         Log.d("FACEBOOK ERROR", 
           "FB ERROR. MSG: " + e.getMessage() 
             + ", CAUSE: " + e.getCause()); 
        } 

        @Override 
        public void onError(DialogError e) { 
         Log.e("ERROR", "AUTH ERROR. MSG: " + e.getMessage() 
           + ", CAUSE: " + e.getCause()); 
        } 

        @Override 
        public void onCancel() { 
         Log.d("CANCELLED", "AUTH CANCELLED"); 
        } 
       }); 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 
    Log.d("onActivityResult", "onActivityResult"); 
    facebook.authorizeCallback(requestCode, resultCode, data); 
}