use of com.facebook.FacebookServiceException in project facebook-android-sdk by facebook.
the class CustomTabLoginMethodHandler method onCustomTabComplete.
private void onCustomTabComplete(String url, LoginClient.Request request) {
if (url != null && url.startsWith(CustomTabMainActivity.getRedirectUrl())) {
Uri uri = Uri.parse(url);
Bundle values = Utility.parseUrlQueryString(uri.getQuery());
values.putAll(Utility.parseUrlQueryString(uri.getFragment()));
if (!validateChallengeParam(values)) {
super.onComplete(request, null, new FacebookException("Invalid state parameter"));
return;
}
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_message");
}
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) {
super.onComplete(request, values, null);
} else if (error != null && (error.equals("access_denied") || error.equals("OAuthAccessDeniedException"))) {
super.onComplete(request, null, new FacebookOperationCanceledException());
} else if (errorCode == API_EC_DIALOG_CANCEL) {
super.onComplete(request, null, new FacebookOperationCanceledException());
} else {
FacebookRequestError requestError = new FacebookRequestError(errorCode, error, errorMessage);
super.onComplete(request, null, new FacebookServiceException(requestError, errorMessage));
}
}
}
use of com.facebook.FacebookServiceException in project facebook-android-sdk by facebook.
the class WebLoginMethodHandler method onComplete.
protected void onComplete(LoginClient.Request request, Bundle values, FacebookException error) {
LoginClient.Result outcome;
e2e = null;
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, getTokenSource(), 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);
}
Aggregations