2013-06-26 70 views
5

當我使用HTC Android時,它表現很好。但是,當我使用Facebook的API登錄使用三星Android 4.2,我顯示Toast消息,如「登錄失敗請聯繫這個應用程序的標記,並要求他們發出1732910到Facebook」當我使用三星Android 4.2時,Facebook登錄不起作用

請幫我解決它!

public class FacebookLogin { 
/* variable Facebook */ 
private static final String FACEBOOK_APPID = "578073962236765"; 
private FacebookConnector facebookConnector; 
private final Handler mFacebookHandler = new Handler(); 
ActivityBase activity; 
Request.GraphUserCallback userCallback; 
LoginService.OnSwimLogedInEvents swimLoginCallBack; 
LoginService loginService; 
Dialog changeDialog; 
LoadingDialog loadingDialog; 

public FacebookLogin(ActivityBase activity, Request.GraphUserCallback userCallback, LoginService.OnSwimLogedInEvents swimLoginCallBack) { 
    this.activity = activity; 
    this.loadingDialog = new LoadingDialog(); 
    this.userCallback = userCallback; 
    this.swimLoginCallBack = swimLoginCallBack; 
    this.loginService = new LoginService(activity); 
    this.facebookConnector = new FacebookConnector(FACEBOOK_APPID, 
      activity, activity, new String[]{ 
      "publish_stream", "email", "user_birthday", "read_stream", "offline_access"}); 
} 

public void login() { 
    Session.initializeStaticContext(activity); 
    if (facebookConnector.getFacebook().isSessionValid()) { 
     facebookConnector.getFacebook().getSession() 
       .closeAndClearTokenInformation(); 
    } 

    AuthListener listener = new AuthListener() { 
     @Override 
     public void onAuthSucceed() { 
      doLogin(); 
     } 

     @Override 
     public void onAuthFail(String error) { 
      //(new MessageAlert()).showDialog("Facebook authetication fail\r\nError:" + error, activity); 
     } 
    }; 
    SessionEvents.addAuthListener(listener); 

    facebookConnector.login(); 
} 

public void onActivityResult(int requestCode, int resultCode, Intent data) { 
    facebookConnector.getFacebook().authorizeCallback(requestCode, resultCode, data); 
} 

private void doLogin() { 
    AsyncTaskBase<Void, Void, Void> t = new AsyncTaskBase<Void, Void, Void>(
      activity) { 
     @Override 
     protected Void doInBackground(Void... params) { 
      mFacebookHandler.post(facebookUserInfoRunner); 
      return super.doInBackground(params); 
     } 

     @Override 
     protected void onPostExecute(Void aVoid) { 
      super.onPostExecute(aVoid); 
     } 
    }; 
    t.execute(); 
} 

final Runnable facebookUserInfoRunner = new Runnable() { 
    @Override 
    public void run() { 
     loadingDialog.showDialogLoading(activity); 
     Request.executeMeRequestAsync(facebookConnector.getFacebook() 
       .getSession(), new Request.GraphUserCallback() { 

      @Override 
      public void onCompleted(GraphUser user, Response response) { 
       SwimAccount currentAccount = ((SwimApp) activity.getApplication()).getCurrentAccount(); 
       currentAccount.setAvatarUrl("https://graph.facebook.com/" + user.getId() + "/picture"); 
       currentAccount.setIsLogin(true); 
       currentAccount.setFirstName(user.getFirstName()); 
       currentAccount.setLastName(user.getLastName()); 
       currentAccount.setStringId(user.getId()); 
       currentAccount.setAccountType("facebook"); 
       currentAccount.setEmail((String) response.getGraphObject().getProperty("email")); 
       currentAccount.setBirthdate(user.getBirthday()); 
       currentAccount.setGender((String) response.getGraphObject().getProperty("gender")); 
       if (userCallback != null) { 
        userCallback.onCompleted(user, response); 
       } 

       loginService.login(currentAccount.getEmail(), "", currentAccount.getAccountType(), currentAccount.getStringId(), swimLoginCallBack); 
       //changeDialog.dismiss(); 
      } 
     }); 
    } 
}; 

}

+0

同樣在這裏請回答。 –

+0

任何解決方案?我遇到與4.2 +的三星S4相同的問題。 – Ron

+0

確保您使用的是最新版本的Facebook sdk。你可以從[這裏](https://developers.facebook.com/android/)中獲得它,並閱讀那裏的基本教程。 – 2013-08-22 15:24:36

回答

2

找到了解決我的問題。嘗試從清單中的Facebook登錄活動中刪除android:noHistory="true"。這與會話的認證流程混淆。

1

它看起來像XDA的人有這個相同的問題。

他們聲稱,你可以嘗試以下任一:

(1)「不保留活動」選項上設置>開發人員選項。如果它處於開啓狀態,那麼當應用程序調用某個彈出窗口時,系統會關閉應用程序,然後系統重新啓動它......並且已經有了您的循環。 (2)如果您卸載Facebook應用程序,則可以通過您的應用程序登錄,然後重新安裝Facebook應用程序。

不知道這些答案是如何「官方」的,但認爲這可能值得一試。

來源: http://forum.xda-developers.com/showthread.php?p=43200939http://forum.xda-developers.com/showthread.php?t=2186035

+0

試過他們,他們沒有幫助。我發佈了我的解決方案(解決了我的問題),但我不確定是否會影響其他人的問題。 – Ron

相關問題