com.facebook.FacebookOperationCanceledException Java Examples

The following examples show how to use com.facebook.FacebookOperationCanceledException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NativeProtocol.java    From kognitivo with Apache License 2.0 6 votes vote down vote up
public static FacebookException getExceptionFromErrorData(Bundle errorData) {
    if (errorData == null) {
        return null;
    }

    String type = errorData.getString(BRIDGE_ARG_ERROR_TYPE);
    if (type == null) {
        type = errorData.getString(STATUS_ERROR_TYPE);
    }

    String description = errorData.getString(BRIDGE_ARG_ERROR_DESCRIPTION);
    if (description == null) {
        description = errorData.getString(STATUS_ERROR_DESCRIPTION);
    }

    if (type != null && type.equalsIgnoreCase(ERROR_USER_CANCELED)) {
        return new FacebookOperationCanceledException(description);
    }

    /* TODO parse error values and create appropriate exception class */
    return new FacebookException(description);
}
 
Example #2
Source File: NativeProtocol.java    From letv with Apache License 2.0 6 votes vote down vote up
public static FacebookException getExceptionFromErrorData(Bundle errorData) {
    if (errorData == null) {
        return null;
    }
    String type = errorData.getString(BRIDGE_ARG_ERROR_TYPE);
    if (type == null) {
        type = errorData.getString(STATUS_ERROR_TYPE);
    }
    String description = errorData.getString(BRIDGE_ARG_ERROR_DESCRIPTION);
    if (description == null) {
        description = errorData.getString(STATUS_ERROR_DESCRIPTION);
    }
    if (type == null || !type.equalsIgnoreCase(ERROR_USER_CANCELED)) {
        return new FacebookException(description);
    }
    return new FacebookOperationCanceledException(description);
}
 
Example #3
Source File: FbDialog.java    From Abelana-Android with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #4
Source File: FbDialog.java    From facebook-api-android-maven with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #5
Source File: ShareInternalUtility.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static boolean handleActivityResult(
        int requestCode,
        int resultCode,
        Intent data,
        ResultProcessor resultProcessor) {
    AppCall appCall = getAppCallFromActivityResult(requestCode, resultCode, data);
    if (appCall == null) {
        return false;
    }

    NativeAppCallAttachmentStore.cleanupAttachmentsForCall(appCall.getCallId());
    if (resultProcessor == null) {
        return true;
    }

    FacebookException exception = NativeProtocol.getExceptionFromErrorData(
            NativeProtocol.getErrorDataFromResultIntent(data));
    if (exception != null) {
        if (exception instanceof FacebookOperationCanceledException) {
            resultProcessor.onCancel(appCall);
        } else {
            resultProcessor.onError(appCall, exception);
        }
    } else {
        // If here, we did not find an error in the result.
        Bundle results = NativeProtocol.getSuccessResultsFromIntent(data);
        resultProcessor.onSuccess(appCall, results);
    }

    return true;
}
 
Example #6
Source File: NativeProtocol.java    From kognitivo with Apache License 2.0 5 votes vote down vote up
public static Bundle createBundleForException(FacebookException e) {
    if (e == null) {
        return null;
    }

    Bundle errorBundle = new Bundle();
    errorBundle.putString(BRIDGE_ARG_ERROR_DESCRIPTION, e.toString());
    if (e instanceof FacebookOperationCanceledException) {
        errorBundle.putString(BRIDGE_ARG_ERROR_TYPE, ERROR_USER_CANCELED);
    }

    return errorBundle;
}
 
Example #7
Source File: NativeProtocol.java    From letv with Apache License 2.0 5 votes vote down vote up
public static Bundle createBundleForException(FacebookException e) {
    if (e == null) {
        return null;
    }
    Bundle errorBundle = new Bundle();
    errorBundle.putString(BRIDGE_ARG_ERROR_DESCRIPTION, e.toString());
    if (!(e instanceof FacebookOperationCanceledException)) {
        return errorBundle;
    }
    errorBundle.putString(BRIDGE_ARG_ERROR_TYPE, ERROR_USER_CANCELED);
    return errorBundle;
}
 
Example #8
Source File: NativeProtocol.java    From Abelana-Android with Apache License 2.0 5 votes vote down vote up
public static Exception getErrorFromResult(Bundle errorBundle) {
    // TODO This is not going to work for JS dialogs, where the keys are not STATUS_ERROR_TYPE etc.
    // TODO However, it should keep existing dialogs functional
    String type = errorBundle.getString(STATUS_ERROR_TYPE);
    String description = errorBundle.getString(STATUS_ERROR_DESCRIPTION);

    if (type != null && type.equalsIgnoreCase(ERROR_USER_CANCELED)) {
        return new FacebookOperationCanceledException(description);
    }

    /* TODO parse error values and create appropriate exception class */
    return new FacebookException(description);
}
 
Example #9
Source File: NativeProtocol.java    From facebook-api-android-maven with Apache License 2.0 5 votes vote down vote up
public static Exception getErrorFromResult(Bundle errorBundle) {
    // TODO This is not going to work for JS dialogs, where the keys are not STATUS_ERROR_TYPE etc.
    // TODO However, it should keep existing dialogs functional
    String type = errorBundle.getString(STATUS_ERROR_TYPE);
    String description = errorBundle.getString(STATUS_ERROR_DESCRIPTION);

    if (type != null && type.equalsIgnoreCase(ERROR_USER_CANCELED)) {
        return new FacebookOperationCanceledException(description);
    }

    /* TODO parse error values and create appropriate exception class */
    return new FacebookException(description);
}
 
Example #10
Source File: WebViewLoginMethodHandler.java    From kognitivo with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #11
Source File: UserTimeline.java    From Klyph with MIT License 4 votes vote down vote up
private void publishFeedDialog()
{
	Bundle params = new Bundle();
	params.putString("from", KlyphSession.getSessionUserId());
	params.putString("to", getElementId());

	WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(getActivity(), Session.getActiveSession(), params)).setOnCompleteListener(
			new WebDialog.OnCompleteListener() {

				@Override
				public void onComplete(Bundle values, FacebookException error)
				{
					if (error == null)
					{
						final String postId = values.getString("post_id");

						if (postId != null)
						{
							Toast.makeText(getActivity(), R.string.message_successfully_published, Toast.LENGTH_SHORT).show();

							loadNewest();
						}
						else
						{
							// User clicked the Cancel button
							Toast.makeText(getActivity().getApplicationContext(), "Publish cancelled", Toast.LENGTH_SHORT).show();
						}
					}
					else if (error instanceof FacebookOperationCanceledException)
					{
						// User clicked the "x" button
						// Toast.makeText(getActivity().getApplicationContext(),
						// "Publish cancelled",
						// Toast.LENGTH_SHORT).show();
					}
					else
					{
						AlertUtil.showAlert(getActivity(), R.string.error, R.string.publish_message_unknown_error, R.string.ok);
					}
				}

			}).build();
	feedDialog.show();
}