public void logAuthorizationMethodComplete(
      String authId,
      String method,
      String result,
      String errorMessage,
      String errorCode,
      Map<String, String> loggingExtras) {

    Bundle bundle;
    bundle = LoginLogger.newAuthorizationLoggingBundle(authId);
    if (result != null) {
      bundle.putString(LoginLogger.EVENT_PARAM_LOGIN_RESULT, result);
    }
    if (errorMessage != null) {
      bundle.putString(LoginLogger.EVENT_PARAM_ERROR_MESSAGE, errorMessage);
    }
    if (errorCode != null) {
      bundle.putString(LoginLogger.EVENT_PARAM_ERROR_CODE, errorCode);
    }
    if (loggingExtras != null && !loggingExtras.isEmpty()) {
      JSONObject jsonObject = new JSONObject(loggingExtras);
      bundle.putString(LoginLogger.EVENT_PARAM_EXTRAS, jsonObject.toString());
    }
    bundle.putString(EVENT_PARAM_METHOD, method);

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_METHOD_COMPLETE, null, bundle);
  }
  public void logUnexpectedError(String eventName, String errorMessage, String method) {
    Bundle bundle = newAuthorizationLoggingBundle("");
    bundle.putString(EVENT_PARAM_LOGIN_RESULT, LoginClient.Result.Code.ERROR.getLoggingValue());
    bundle.putString(EVENT_PARAM_ERROR_MESSAGE, errorMessage);
    bundle.putString(EVENT_PARAM_METHOD, method);

    appEventsLogger.logSdkEvent(eventName, null, bundle);
  }
  public void logStartLogin(LoginClient.Request pendingLoginRequest) {
    Bundle bundle = newAuthorizationLoggingBundle(pendingLoginRequest.getAuthId());

    // Log what we already know about the call in start event
    try {
      JSONObject extras = new JSONObject();
      extras.put(EVENT_EXTRAS_LOGIN_BEHAVIOR, pendingLoginRequest.getLoginBehavior().toString());
      extras.put(EVENT_EXTRAS_REQUEST_CODE, LoginClient.getLoginRequestCode());
      extras.put(
          EVENT_EXTRAS_PERMISSIONS, TextUtils.join(",", pendingLoginRequest.getPermissions()));
      extras.put(
          EVENT_EXTRAS_DEFAULT_AUDIENCE, pendingLoginRequest.getDefaultAudience().toString());
      extras.put(EVENT_EXTRAS_IS_REAUTHORIZE, pendingLoginRequest.isRerequest());
      bundle.putString(EVENT_PARAM_EXTRAS, extras.toString());
    } catch (JSONException e) {
    }

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_START, null, bundle);
  }
  public void logCompleteLogin(
      String loginRequestId,
      Map<String, String> loggingExtras,
      LoginClient.Result.Code result,
      Map<String, String> resultExtras,
      Exception exception) {

    Bundle bundle = newAuthorizationLoggingBundle(loginRequestId);
    if (result != null) {
      bundle.putString(EVENT_PARAM_LOGIN_RESULT, result.getLoggingValue());
    }
    if (exception != null && exception.getMessage() != null) {
      bundle.putString(EVENT_PARAM_ERROR_MESSAGE, exception.getMessage());
    }

    // Combine extras from the request and from the result.
    JSONObject jsonObject = null;
    if (loggingExtras.isEmpty() == false) {
      jsonObject = new JSONObject(loggingExtras);
    }
    if (resultExtras != null) {
      if (jsonObject == null) {
        jsonObject = new JSONObject();
      }
      try {
        for (Map.Entry<String, String> entry : resultExtras.entrySet()) {
          jsonObject.put(entry.getKey(), entry.getValue());
        }
      } catch (JSONException e) {
      }
    }
    if (jsonObject != null) {
      bundle.putString(EVENT_PARAM_EXTRAS, jsonObject.toString());
    }

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_COMPLETE, null, bundle);
  }
Beispiel #5
0
    @Override
    public void onClick(View v) {
      callExternalOnClickListener(v);

      Context context = getContext();

      AccessToken accessToken = AccessToken.getCurrentAccessToken();

      if (accessToken != null) {
        // Log out
        if (confirmLogout) {
          // Create a confirmation dialog
          String logout = getResources().getString(R.string.com_facebook_loginview_log_out_action);
          String cancel = getResources().getString(R.string.com_facebook_loginview_cancel_action);
          String message;
          Profile profile = Profile.getCurrentProfile();
          if (profile != null && profile.getName() != null) {
            message =
                String.format(
                    getResources().getString(R.string.com_facebook_loginview_logged_in_as),
                    profile.getName());
          } else {
            message =
                getResources().getString(R.string.com_facebook_loginview_logged_in_using_facebook);
          }
          AlertDialog.Builder builder = new AlertDialog.Builder(context);
          builder
              .setMessage(message)
              .setCancelable(true)
              .setPositiveButton(
                  logout,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                      getLoginManager().logOut();
                    }
                  })
              .setNegativeButton(cancel, null);
          builder.create().show();
        } else {
          getLoginManager().logOut();
        }
      } else {
        LoginManager loginManager = getLoginManager();
        loginManager.setDefaultAudience(getDefaultAudience());
        loginManager.setLoginBehavior(getLoginBehavior());

        if (LoginAuthorizationType.PUBLISH.equals(properties.authorizationType)) {
          if (LoginButton.this.getFragment() != null) {
            loginManager.logInWithPublishPermissions(
                LoginButton.this.getFragment(), properties.permissions);
          } else {
            loginManager.logInWithPublishPermissions(
                LoginButton.this.getActivity(), properties.permissions);
          }
        } else {
          if (LoginButton.this.getFragment() != null) {
            loginManager.logInWithReadPermissions(
                LoginButton.this.getFragment(), properties.permissions);
          } else {
            loginManager.logInWithReadPermissions(
                LoginButton.this.getActivity(), properties.permissions);
          }
        }
      }

      AppEventsLogger logger = AppEventsLogger.newLogger(getContext());

      Bundle parameters = new Bundle();
      parameters.putInt("logging_in", (accessToken != null) ? 0 : 1);

      logger.logSdkEvent(loginLogoutEventName, null, parameters);
    }
  public void logAuthorizationMethodStart(String authId, String method) {
    Bundle bundle = LoginLogger.newAuthorizationLoggingBundle(authId);
    bundle.putString(EVENT_PARAM_METHOD, method);

    appEventsLogger.logSdkEvent(EVENT_NAME_LOGIN_METHOD_START, null, bundle);
  }