1
我使用FB SDK 4.5.1版與eclipse登錄到Facebook。有時它會成功登錄,但有些時候會出現此錯誤消息「CONNECTION FAILURE」。這是我的互聯網連接或代碼問題嗎?FB SDK(4.5.1)登錄:連接失敗
這裏是我的代碼:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
Log.d(TAG,"Fb initialzed");
callbackManager = CallbackManager.Factory.create();
//LoginButton loginButton= (LoginButton)findViewById(R.id.fb_login_button);
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult result) {
// TODO Auto-generated method stub
Log.d(TAG,"Login success");
Intent I = new Intent(getApplicationContext(), Games.class);
startActivity(I);
}
private void showAlert() {
new AlertDialog.Builder(GameSurvey.this)
.setTitle(R.string.cancelled)
.setMessage(R.string.permission_not_granted)
.setPositiveButton(R.string.ok, null)
.show();
}
@Override
public void onCancel() {
// TODO Auto-generated method stub
Log.d(TAG,"Login cancelled");
}
@Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
if(error instanceof FacebookAuthorizationException)
Log.d(TAG,error.toString());
showAlert();
}
});
Log.d(TAG, "here");
setContentView(R.layout.activity_game_survey);
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {
updateUI();
// It's possible that we were waiting for Profile to be populated in order to
// post a status update.
}
};
profilePictureView = (ProfilePictureView) findViewById(R.id.profilePicture);
}
你在'onError'回調中得到了這個嗎?如果是這樣,那麼這很可能是一個連接問題。 – ifaour
@ifaour是的,您可以發表您的評論作爲答案,以便我可以接受它。 – Alaa