Exemplo n.º 1
0
  private UserProfile createUserProfile(User user, boolean withExtraFields) {
    String fullName = user.getName();
    String firstName = "";
    String lastName = "";

    if (!TextUtils.isEmpty(fullName)) {
      String[] splitName = fullName.split(" ");
      if (splitName.length > 0) {
        firstName = splitName[0];
        if (splitName.length > 1) {
          lastName = splitName[1];
        }
      }
    }
    Map<String, Object> extraDict = Collections.<String, Object>emptyMap();
    if (withExtraFields) {
      extraDict = new HashMap<String, Object>();
      // TwitterException will throws when Twitter service or network is unavailable, or the user
      // has not authorized
      try {
        extraDict.put("access_token", twitter.getOAuthAccessToken().getToken());
      } catch (TwitterException twitterExc) {
        SoomlaUtils.LogError(TAG, twitterExc.getErrorMessage());
      }
    }
    // Twitter does not supply email access: https://dev.twitter.com/faq#26
    UserProfile result =
        new UserProfile(
            RefProvider,
            String.valueOf(user.getId()),
            user.getScreenName(),
            "",
            firstName,
            lastName,
            extraDict);

    // No gender information on Twitter:
    // https://twittercommunity.com/t/how-to-find-male-female-accounts-in-following-list/7367
    result.setGender("");

    // No birthday on Twitter:
    // https://twittercommunity.com/t/how-can-i-get-email-of-user-if-i-use-api/7019/16
    result.setBirthday("");

    result.setLanguage(user.getLang());
    result.setLocation(user.getLocation());
    result.setAvatarLink(user.getBiggerProfileImageURL());

    return result;
  }
Exemplo n.º 2
0
  /** {@inheritDoc} */
  @Override
  public void configure(Map<String, String> providerParams) {
    autoLogin = false;

    if (providerParams != null) {
      twitterConsumerKey = providerParams.get("consumerKey");
      twitterConsumerSecret = providerParams.get("consumerSecret");

      // extract autoLogin
      String autoLoginStr = providerParams.get("autoLogin");
      autoLogin = autoLoginStr != null && Boolean.parseBoolean(autoLoginStr);
    }

    SoomlaUtils.LogDebug(
        TAG,
        String.format(
            "ConsumerKey:%s ConsumerSecret:%s", twitterConsumerKey, twitterConsumerSecret));

    if (TextUtils.isEmpty(twitterConsumerKey) || TextUtils.isEmpty(twitterConsumerSecret)) {
      SoomlaUtils.LogError(
          TAG,
          "You must provide the Consumer Key and Secret in the SoomlaProfile initialization parameters");
      isInitialized = false;
    } else {
      isInitialized = true;
    }

    oauthCallbackURL = "oauth://soomla_twitter" + twitterConsumerKey;

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
    configurationBuilder.setOAuthConsumerKey(twitterConsumerKey);
    configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret);
    Configuration configuration = configurationBuilder.build();
    twitter = new AsyncTwitterFactory(configuration).getInstance();

    if (!actionsListenerAdded) {
      SoomlaUtils.LogWarning(TAG, "added action listener");
      twitter.addListener(actionsListener);
      actionsListenerAdded = true;
    }
  }