Search in sources :

Example 1 with FacebookRequestError

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));
        }
    }
}
Also used : FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) FacebookServiceException(com.facebook.FacebookServiceException) Uri(android.net.Uri) FacebookRequestError(com.facebook.FacebookRequestError)

Example 2 with FacebookRequestError

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));
            }
        }
    });
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle) FacebookException(com.facebook.FacebookException) JSONException(org.json.JSONException) FacebookRequestError(com.facebook.FacebookRequestError)

Example 3 with FacebookRequestError

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();
}
Also used : GraphRequest(com.facebook.GraphRequest) JSONObject(org.json.JSONObject) GraphResponse(com.facebook.GraphResponse) Bundle(android.os.Bundle) JSONException(org.json.JSONException) FacebookRequestError(com.facebook.FacebookRequestError)

Example 4 with FacebookRequestError

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);
    }
}
Also used : FacebookRequestError(com.facebook.FacebookRequestError)

Example 5 with FacebookRequestError

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();
}
Also used : DialogInterface(android.content.DialogInterface) FacebookRequestError(com.facebook.FacebookRequestError)

Aggregations

FacebookRequestError (com.facebook.FacebookRequestError)20 JSONObject (org.json.JSONObject)10 GraphRequest (com.facebook.GraphRequest)9 JSONException (org.json.JSONException)9 GraphResponse (com.facebook.GraphResponse)8 Bundle (android.os.Bundle)7 FacebookException (com.facebook.FacebookException)6 Uri (android.net.Uri)3 ArrayList (java.util.ArrayList)3 JSONArray (org.json.JSONArray)3 FacebookCallback (com.facebook.FacebookCallback)2 FacebookGraphResponseException (com.facebook.FacebookGraphResponseException)2 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)2 FacebookServiceException (com.facebook.FacebookServiceException)2 Request (com.facebook.Request)2 GraphUserListCallback (com.facebook.Request.GraphUserListCallback)2 Response (com.facebook.Response)2 Session (com.facebook.Session)2 GraphUser (com.facebook.model.GraphUser)2 List (java.util.List)2