Search in sources :

Example 1 with FacebookAuthorizationException

use of com.facebook.FacebookAuthorizationException 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 2 with FacebookAuthorizationException

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

the class LoginManager method onActivityResult.

boolean onActivityResult(int resultCode, Intent data, FacebookCallback<LoginResult> callback) {
    FacebookException exception = null;
    AccessToken newToken = null;
    LoginClient.Result.Code code = LoginClient.Result.Code.ERROR;
    Map<String, String> loggingExtras = null;
    LoginClient.Request originalRequest = null;
    boolean isCanceled = false;
    if (data != null) {
        LoginClient.Result result = data.getParcelableExtra(LoginFragment.RESULT_KEY);
        if (result != null) {
            originalRequest = result.request;
            code = result.code;
            if (resultCode == Activity.RESULT_OK) {
                if (result.code == LoginClient.Result.Code.SUCCESS) {
                    newToken = result.token;
                } else {
                    exception = new FacebookAuthorizationException(result.errorMessage);
                }
            } else if (resultCode == Activity.RESULT_CANCELED) {
                isCanceled = true;
            }
            loggingExtras = result.loggingExtras;
        }
    } else if (resultCode == Activity.RESULT_CANCELED) {
        isCanceled = true;
        code = LoginClient.Result.Code.CANCEL;
    }
    if (exception == null && newToken == null && !isCanceled) {
        exception = new FacebookException("Unexpected call to LoginManager.onActivityResult");
    }
    boolean wasLoginActivityTried = true;
    //Sadly, there is no way to get activity context at this point.S
    Context context = null;
    logCompleteLogin(context, code, loggingExtras, exception, wasLoginActivityTried, originalRequest);
    finishLogin(newToken, originalRequest, exception, isCanceled, callback);
    return true;
}
Also used : FacebookAuthorizationException(com.facebook.FacebookAuthorizationException) Context(android.content.Context) FacebookException(com.facebook.FacebookException) AccessToken(com.facebook.AccessToken)

Aggregations

FacebookAuthorizationException (com.facebook.FacebookAuthorizationException)2 Context (android.content.Context)1 AccessToken (com.facebook.AccessToken)1 FacebookException (com.facebook.FacebookException)1 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)1 Request (com.facebook.Request)1 GraphUserCallback (com.facebook.Request.GraphUserCallback)1 Response (com.facebook.Response)1 Session (com.facebook.Session)1 GraphObject (com.facebook.model.GraphObject)1 GraphUser (com.facebook.model.GraphUser)1