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); }
private void parseFacebookRequestError(Bundle values, FacebookException facebookException) { if (facebookException != null) { if (facebookException instanceof FacebookOperationCanceledException) { DialogUtils.showLong(activity, resources.getString(R.string.inf_fb_request_canceled)); } else if (facebookException instanceof FacebookServiceException) { final int errorCodeCancel = 4201; FacebookServiceException facebookServiceException = (FacebookServiceException) facebookException; if (errorCodeCancel == facebookServiceException.getRequestError().getErrorCode()) { DialogUtils.showLong(activity, resources.getString(R.string.inf_fb_request_canceled)); } else { ErrorUtils.showError( activity, facebookServiceException.getRequestError().getErrorMessage()); } } else if (!TextUtils.isEmpty(facebookException.getMessage())) { ErrorUtils.showError(activity, facebookException); } } else { final String requestId = values.getString("request"); if (requestId != null) { DialogUtils.showLong(activity, resources.getString(R.string.dlg_success_request_facebook)); } else { DialogUtils.showLong(activity, resources.getString(R.string.inf_fb_request_canceled)); } } }
@Override public void onComplete(Bundle values, FacebookException error) { if (error != null) { nativeCallback(mCallbackIndex, "null"); error.printStackTrace(); } else { if (values != null) { Set<String> keySet = values.keySet(); JSONObject jsonObject = new JSONObject(); for (String key : keySet) { Object valueObject = values.get(key); try { if (valueObject instanceof String) jsonObject.put(key, (String) valueObject); else if (valueObject instanceof Integer) jsonObject.put(key, ((Integer) valueObject).intValue()); else if (valueObject instanceof Double) jsonObject.put(key, ((Double) valueObject).doubleValue()); else if (valueObject instanceof Boolean) jsonObject.put(key, ((Boolean) valueObject).booleanValue()); else if (valueObject instanceof JSONObject) jsonObject.put(key, valueObject); } catch (JSONException e) { e.printStackTrace(); } } nativeCallback(mCallbackIndex, jsonObject.toString()); } } }
private void handleError(FacebookException exception, CallbackContext context) { if (exception.getMessage() != null) { Log.e(TAG, exception.toString()); } String errMsg = "Facebook error: " + exception.getMessage(); int errorCode = INVALID_ERROR_CODE; // User clicked "x" if (exception instanceof FacebookOperationCanceledException) { errMsg = "User cancelled dialog"; errorCode = 4201; } else if (exception instanceof FacebookDialogException) { // Dialog error errMsg = "Dialog error: " + exception.getMessage(); } context.error(getErrorResponse(exception, errMsg, errorCode)); }
private void callDialogListener(Bundle values, FacebookException error) { if (mListener == null) { return; } if (values != null) { mListener.onComplete(values); } else { if (error instanceof FacebookDialogException) { FacebookDialogException facebookDialogException = (FacebookDialogException) error; DialogError dialogError = new DialogError( facebookDialogException.getMessage(), facebookDialogException.getErrorCode(), facebookDialogException.getFailingUrl()); mListener.onError(dialogError); } else if (error instanceof FacebookOperationCanceledException) { mListener.onCancel(); } else { FacebookError facebookError = new FacebookError(error.getMessage()); mListener.onFacebookError(facebookError); } } }
@Override public void onError(FacebookException e) { changeCurrentState(StatusFacebookConn.DISCONNECTED); Log.e(TAGERROR, e.getMessage()); }
@Override public void onError(final FacebookException error) { error.printStackTrace(); }