Search in sources :

Example 6 with FacebookOperationCanceledException

use of com.facebook.FacebookOperationCanceledException in project Klyph by jonathangerbaud.

the class UserTimeline method publishFeedDialog.

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();
}
Also used : FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) Bundle(android.os.Bundle) WebDialog(com.facebook.widget.WebDialog) FacebookException(com.facebook.FacebookException)

Example 7 with FacebookOperationCanceledException

use of com.facebook.FacebookOperationCanceledException in project phonegap-facebook-plugin by Wizcorp.

the class FbDialog method callDialogListener.

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

Example 8 with FacebookOperationCanceledException

use of com.facebook.FacebookOperationCanceledException in project phonegap-facebook-plugin by Wizcorp.

the class ConnectPlugin method onSessionStateChange.

/*
     * Handles session state changes
     */
private void onSessionStateChange(SessionState state, Exception exception) {
    Log.d(TAG, "onSessionStateChange:" + state.toString());
    if (exception != null && exception instanceof FacebookOperationCanceledException) {
        // only handle FacebookOperationCanceledException to support
        // SDK recovery behavior triggered by getUserInfo
        Log.e(TAG, "exception:" + exception.toString());
        handleError(exception, loginContext);
    } else {
        final Session session = Session.getActiveSession();
        // Check if the session is open
        if (state.isOpened()) {
            if (loginContext != null) {
                // Get user info
                getUserInfo(session, new Request.GraphUserCallback() {

                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        // Create a new result with response data
                        if (loginContext != null) {
                            if (response.getError() != null) {
                                loginContext.error(getFacebookRequestErrorResponse(response.getError()));
                            } else {
                                GraphObject graphObject = response.getGraphObject();
                                Log.d(TAG, "returning login object " + graphObject.getInnerJSONObject().toString());
                                userID = user.getId();
                                loginContext.success(getResponse());
                                loginContext = null;
                            }
                        } else {
                            // Just update the userID in case we force quit the application before
                            userID = user.getId();
                        }
                    }
                });
            } else if (graphContext != null) {
                // Make the graph call
                makeGraphCall();
            }
        } else if (state == SessionState.CLOSED_LOGIN_FAILED && loginContext != null) {
            handleError(new FacebookAuthorizationException("Session was closed and was not closed normally"), loginContext);
        }
    }
}
Also used : Response(com.facebook.Response) FacebookAuthorizationException(com.facebook.FacebookAuthorizationException) FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) GraphUser(com.facebook.model.GraphUser) GraphUserCallback(com.facebook.Request.GraphUserCallback) Request(com.facebook.Request) GraphObject(com.facebook.model.GraphObject) Session(com.facebook.Session)

Example 9 with FacebookOperationCanceledException

use of com.facebook.FacebookOperationCanceledException 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);
}
Also used : FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) AccessToken(com.facebook.AccessToken) CookieSyncManager(android.webkit.CookieSyncManager) FacebookException(com.facebook.FacebookException) FacebookServiceException(com.facebook.FacebookServiceException) FacebookRequestError(com.facebook.FacebookRequestError)

Example 10 with FacebookOperationCanceledException

use of com.facebook.FacebookOperationCanceledException in project facebook-android-sdk by facebook.

the class WebViewLoginMethodHandlerTest method testWebViewHandlesCancel.

@Test
public void testWebViewHandlesCancel() {
    WebViewLoginMethodHandler handler = new WebViewLoginMethodHandler(mockLoginClient);
    LoginClient.Request request = createRequest();
    handler.onWebDialogComplete(request, null, new FacebookOperationCanceledException());
    ArgumentCaptor<LoginClient.Result> resultArgumentCaptor = ArgumentCaptor.forClass(LoginClient.Result.class);
    verify(mockLoginClient, times(1)).completeAndValidate(resultArgumentCaptor.capture());
    LoginClient.Result result = resultArgumentCaptor.getValue();
    assertNotNull(result);
    assertEquals(LoginClient.Result.Code.CANCEL, result.code);
    assertNull(result.token);
    assertNotNull(result.errorMessage);
}
Also used : FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)11 Bundle (android.os.Bundle)4 FacebookException (com.facebook.FacebookException)4 FacebookDialogException (com.facebook.FacebookDialogException)2 FacebookRequestError (com.facebook.FacebookRequestError)2 FacebookServiceException (com.facebook.FacebookServiceException)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Uri (android.net.Uri)1 CookieSyncManager (android.webkit.CookieSyncManager)1 AccessToken (com.facebook.AccessToken)1 FacebookAuthorizationException (com.facebook.FacebookAuthorizationException)1 Request (com.facebook.Request)1 GraphUserCallback (com.facebook.Request.GraphUserCallback)1 Response (com.facebook.Response)1 Session (com.facebook.Session)1 AppCall (com.facebook.internal.AppCall)1 GraphObject (com.facebook.model.GraphObject)1 GraphUser (com.facebook.model.GraphUser)1 WebDialog (com.facebook.widget.WebDialog)1