private void onCompleteConnect(int resultCode, Intent data) {
    AuthCodeResponse codeResponse = FoursquareOAuth.getAuthCodeFromResult(resultCode, data);
    Exception exception = codeResponse.getException();

    if (exception == null) {
      // Success.
      String code = codeResponse.getCode();
      performTokenExchange(code);

    } else {
      if (exception instanceof FoursquareCancelException) {
        // Cancel.
        toastMessage(this, "Canceled");

      } else if (exception instanceof FoursquareDenyException) {
        // Deny.
        toastMessage(this, "Denied");

      } else if (exception instanceof FoursquareOAuthException) {
        // OAuth error.
        String errorMessage = exception.getMessage();
        String errorCode = ((FoursquareOAuthException) exception).getErrorCode();
        toastMessage(this, errorMessage + " [" + errorCode + "]");

      } else if (exception instanceof FoursquareUnsupportedVersionException) {
        // Unsupported Fourquare app version on the device.
        toastError(this, exception);

      } else if (exception instanceof FoursquareInvalidRequestException) {
        // Invalid request.
        toastError(this, exception);

      } else {
        // Error.
        toastError(this, exception);
      }
    }
  }