void onWebDialogComplete(LoginClient.Request request, Bundle values, FacebookException error) { LoginClient.Result outcome; if (values != null) { // Actual e2e we got from the dialog should be used for logging. if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) { e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E); } try { AccessToken token = createAccessTokenFromWebBundle( request.getPermissions(), values, AccessTokenSource.WEB_VIEW, request.getApplicationId()); outcome = LoginClient.Result.createTokenResult( loginClient.getPendingRequest(), token); // Ensure any cookies set by the dialog are saved // This is to work around a bug where CookieManager may fail to instantiate if // CookieSyncManager has never been created. CookieSyncManager syncManager = CookieSyncManager.createInstance(loginClient.getActivity()); syncManager.sync(); saveCookieToken(token.getToken()); } catch (FacebookException ex) { outcome = LoginClient.Result.createErrorResult( loginClient.getPendingRequest(), null, ex.getMessage()); } } else { if (error instanceof FacebookOperationCanceledException) { outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(), "User canceled log in."); } else { // Something went wrong, don't log a completion event since it will skew timing // results. e2e = null; String errorCode = null; String errorMessage = error.getMessage(); if (error instanceof FacebookServiceException) { FacebookRequestError requestError = ((FacebookServiceException)error).getRequestError(); errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode()); errorMessage = requestError.toString(); } outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, errorMessage, errorCode); } } if (!Utility.isNullOrEmpty(e2e)) { logWebLoginCompleted(e2e); } loginClient.completeAndValidate(outcome); }
@Override @SuppressWarnings("deprecation") public boolean shouldOverrideUrlLoading(WebView view, String url) { Utility.logd(LOG_TAG, "Redirect URL: " + url); if (url.startsWith(WebDialog.REDIRECT_URI)) { Bundle values = Util.parseUrl(url); String error = values.getString("error"); if (error == null) { error = values.getString("error_type"); } String errorMessage = values.getString("error_msg"); if (errorMessage == null) { errorMessage = values.getString("error_description"); } String errorCodeString = values.getString("error_code"); int errorCode = FacebookRequestError.INVALID_ERROR_CODE; if (!Utility.isNullOrEmpty(errorCodeString)) { try { errorCode = Integer.parseInt(errorCodeString); } catch (NumberFormatException ex) { errorCode = FacebookRequestError.INVALID_ERROR_CODE; } } if (Utility.isNullOrEmpty(error) && Utility .isNullOrEmpty(errorMessage) && errorCode == FacebookRequestError.INVALID_ERROR_CODE) { sendSuccessToListener(values); } else if (error != null && (error.equals("access_denied") || error.equals("OAuthAccessDeniedException"))) { sendCancelToListener(); } else { FacebookRequestError requestError = new FacebookRequestError(errorCode, error, errorMessage); sendErrorToListener(new FacebookServiceException(requestError, errorMessage)); } WebDialog.this.dismiss(); return true; } else if (url.startsWith(WebDialog.CANCEL_URI)) { sendCancelToListener(); WebDialog.this.dismiss(); return true; } else if (url.contains(DISPLAY_TOUCH)) { return false; } // launch non-dialog URLs in a full browser getContext().startActivity( new Intent(Intent.ACTION_VIEW, Uri.parse(url))); return true; }