/** * IMPORTANT: This method must be invoked at the top of the calling activity's onActivityResult() * function or Facebook authentication will not function properly! * * <p>If your calling activity does not currently implement onActivityResult(), you must implement * it and include a call to this method if you intend to use the authorize() method in this SDK. * * <p>For more information, see http://developer.android.com/reference/android/app/ * Activity.html#onActivityResult(int, int, android.content.Intent) */ public void authorizeCallback(int requestCode, int resultCode, Intent data) { if (requestCode == mAuthActivityCode) { // Successfully redirected. if (resultCode == Activity.RESULT_OK) { // Check OAuth 2.0/2.10 error code. String error = data.getStringExtra("error"); if (error == null) { error = data.getStringExtra("error_type"); } // A Facebook error occurred. if (error != null) { if (error.equals(SINGLE_SIGN_ON_DISABLED) || error.equals("AndroidAuthKillSwitchException")) { Log.d( "Facebook-authorize", "Hosted auth currently " + "disabled. Retrying dialog auth..."); startDialogAuth(mAuthActivity, mAuthPermissions); } else if (error.equals("access_denied") || error.equals("OAuthAccessDeniedException")) { Log.d("Facebook-authorize", "Login canceled by user."); mAuthDialogListener.onCancel(); } else { String description = data.getStringExtra("error_description"); if (description != null) { error = error + ":" + description; } Log.d("Facebook-authorize", "Login failed: " + error); mAuthDialogListener.onFacebookError(new FacebookError(error)); } // No errors. } else { setAccessToken(data.getStringExtra(TOKEN)); setAccessExpiresIn(data.getStringExtra(EXPIRES)); if (isSessionValid()) { Log.d( "Facebook-authorize", "Login Success! access_token=" + getAccessToken() + " expires=" + getAccessExpires()); mAuthDialogListener.onComplete(data.getExtras()); } else { mAuthDialogListener.onFacebookError( new FacebookError("Failed to receive access token.")); } } // An error occurred before we could be redirected. } else if (resultCode == Activity.RESULT_CANCELED) { // An Android error occured. if (data != null) { Log.d("Facebook-authorize", "Login failed: " + data.getStringExtra("error")); mAuthDialogListener.onError( new DialogError( data.getStringExtra("error"), data.getIntExtra("error_code", -1), data.getStringExtra("failing_url"))); // User pressed the 'back' button. } else { Log.d("Facebook-authorize", "Login canceled by user."); mAuthDialogListener.onCancel(); } } } }
private void cancelBox() { listener.onCancel(); this.setVisible(false); }