use of com.facebook.FacebookRequestError 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.FacebookRequestError in project facebook-android-sdk by facebook.
the class DeviceAuthDialog method getPollRequest.
private GraphRequest getPollRequest() {
Bundle parameters = new Bundle();
parameters.putString("code", currentRequestState.getRequestCode());
return new GraphRequest(null, DEVICE_LOGIN_STATUS_ENDPOINT, parameters, HttpMethod.POST, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
// Check if the request was already cancelled
if (completed.get()) {
return;
}
FacebookRequestError error = response.getError();
if (error != null) {
// message text
switch(error.getSubErrorCode()) {
case LOGIN_ERROR_SUBCODE_AUTHORIZATION_PENDING:
case LOGIN_ERROR_SUBCODE_EXCESSIVE_POLLING:
{
// Keep polling. If we got the slow down message just ignore
schedulePoll();
}
break;
case LOGIN_ERROR_SUBCODE_CODE_EXPIRED:
case LOGIN_ERROR_SUBCODE_AUTHORIZATION_DECLINED:
{
onCancel();
}
break;
default:
{
onError(response.getError().getException());
}
break;
}
return;
}
try {
JSONObject resultObject = response.getJSONObject();
onSuccess(resultObject.getString("access_token"));
} catch (JSONException ex) {
onError(new FacebookException(ex));
}
}
});
}
use of com.facebook.FacebookRequestError in project facebook-android-sdk by facebook.
the class DeviceShareDialogFragment method startShare.
private void startShare() {
Bundle parameters = getGraphParametersForShareContent();
if (parameters == null || parameters.size() == 0) {
this.finishActivityWithError(new FacebookRequestError(0, "", "Failed to get share content"));
}
String accessToken = Validate.hasAppID() + "|" + Validate.hasClientToken();
parameters.putString(GraphRequest.ACCESS_TOKEN_PARAM, accessToken);
parameters.putString(DeviceRequestsHelper.DEVICE_INFO_PARAM, DeviceRequestsHelper.getDeviceInfo());
GraphRequest graphRequest = new GraphRequest(null, DEVICE_SHARE_ENDPOINT, parameters, HttpMethod.POST, new GraphRequest.Callback() {
@Override
public void onCompleted(GraphResponse response) {
FacebookRequestError error = response.getError();
if (error != null) {
finishActivityWithError(error);
return;
}
JSONObject jsonObject = response.getJSONObject();
RequestState requestState = new RequestState();
try {
requestState.setUserCode(jsonObject.getString("user_code"));
requestState.setExpiresIn(jsonObject.getLong("expires_in"));
} catch (JSONException ex) {
finishActivityWithError(new FacebookRequestError(0, "", "Malformed server response"));
return;
}
setCurrentRequestState(requestState);
}
});
graphRequest.executeAsync();
}
use of com.facebook.FacebookRequestError in project facebook-android-sdk by facebook.
the class ShareInternalUtility method invokeCallbackWithResults.
public static void invokeCallbackWithResults(FacebookCallback<Sharer.Result> callback, final String postId, final GraphResponse graphResponse) {
FacebookRequestError requestError = graphResponse.getError();
if (requestError != null) {
String errorMessage = requestError.getErrorMessage();
if (Utility.isNullOrEmpty(errorMessage)) {
errorMessage = "Unexpected error sharing.";
}
invokeOnErrorCallback(callback, graphResponse, errorMessage);
} else {
invokeOnSuccessCallback(callback, postId);
}
}
use of com.facebook.FacebookRequestError in project facebook-android-sdk by facebook.
the class SelectionFragment method handleError.
private void handleError(GraphResponse response) {
FacebookRequestError error = response.getError();
DialogInterface.OnClickListener listener = null;
String dialogBody = null;
if (error == null) {
dialogBody = getString(R.string.error_dialog_default_text);
} else {
switch(error.getCategory()) {
case LOGIN_RECOVERABLE:
// There is a login issue that can be resolved by the LoginManager.
LoginManager.getInstance().resolveError(this, response);
return;
case TRANSIENT:
dialogBody = getString(R.string.error_transient);
break;
case OTHER:
default:
// an unknown issue occurred, this could be a code error, or
// a server side issue, log the issue, and either ask the
// user to retry, or file a bug
dialogBody = getString(R.string.error_unknown, error.getErrorMessage());
break;
}
}
String title = error.getErrorUserTitle();
String message = error.getErrorUserMessage();
if (message == null) {
message = dialogBody;
}
if (title == null) {
title = getResources().getString(R.string.error_dialog_title);
}
new AlertDialog.Builder(getActivity()).setPositiveButton(R.string.error_dialog_button_text, listener).setTitle(title).setMessage(message).show();
}
Aggregations