Пример #1
0
 /**
  * Transforms a twitter4j.Status object into a JSONObject
  *
  * @param pStatus a twitter4j.Status object
  * @return JSONObject
  */
 @SuppressWarnings("unchecked")
 public static JSONObject getJson(Status pStatus) {
   JSONObject jsonObj = null;
   if (pStatus != null) {
     jsonObj = new JSONObject();
     jsonObj.put("createdAt", pStatus.getCreatedAt());
     jsonObj.put("id", pStatus.getId());
     jsonObj.put("text", pStatus.getText());
     jsonObj.put("source", pStatus.getSource());
     jsonObj.put("isTruncated", pStatus.isTruncated());
     jsonObj.put("inReplyToStatusId", pStatus.getInReplyToStatusId());
     jsonObj.put("inReplyToUserId", pStatus.getInReplyToUserId());
     jsonObj.put("isFavorited", pStatus.isFavorited());
     jsonObj.put("isRetweeted", pStatus.isRetweeted());
     jsonObj.put("favoriteCount", pStatus.getFavoriteCount());
     jsonObj.put("inReplyToScreenName", pStatus.getInReplyToScreenName());
     jsonObj.put("geoLocation", pStatus.getGeoLocation());
     jsonObj.put("place", pStatus.getPlace());
     jsonObj.put("retweetCount", pStatus.getRetweetCount());
     jsonObj.put("isPossiblySensitive", pStatus.isPossiblySensitive());
     jsonObj.put("isoLanguageCode", pStatus.getIsoLanguageCode());
     jsonObj.put("contributorsIDs", pStatus.getContributors());
     jsonObj.put("retweetedStatus", pStatus.getRetweetedStatus());
     jsonObj.put("userMentionEntities", pStatus.getUserMentionEntities());
     jsonObj.put("urlEntities", pStatus.getURLEntities());
     jsonObj.put("hashtagEntities", pStatus.getHashtagEntities());
     jsonObj.put("mediaEntities", pStatus.getMediaEntities());
     jsonObj.put("currentUserRetweetId", pStatus.getCurrentUserRetweetId());
     jsonObj.put("user", pStatus.getUser());
   }
   return jsonObj;
 }
Пример #2
0
  public List<String> showReplies(String reply, String sName) {

    List<String> replyToList = new ArrayList<String>();
    String screenName = sName;
    long replyToId = Long.parseLong(reply);
    RateLimitationChecker limit = new RateLimitationChecker(twitter);
    int rateLimit = limit.checkLimitStatusForEndpoint("/statuses/show/:id");
    try {
      while (replyToId > -1) {
        if (rateLimit > 1) {

          replyToList.add(String.valueOf(replyToId));
          replyToList.add(screenName);
          Status status = twitter.showStatus(replyToId);
          String name = status.getUser().getName();
          String text = status.getText();
          replyToList.add(name);
          replyToList.add(text);
          if (status.getInReplyToStatusId() != 0) {
            replyToId = status.getInReplyToStatusId();
            screenName = status.getInReplyToScreenName();
          }
        }
      }

    } catch (TwitterException e) {
      log.debug("Exception why trying to getName of replyToUser", e);
    }
    return replyToList;
  }
Пример #3
0
 private List<String> isReplyTo(Status status, RateLimitationChecker rateLimitationChecker) {
   List<String> replyTo = new ArrayList<String>();
   String inReplyToStatusId = String.valueOf(status.getInReplyToStatusId());
   if (!"-1".equals(inReplyToStatusId)) {
     replyTo.add(inReplyToStatusId);
     replyTo.add(status.getInReplyToScreenName());
   } else {
     replyTo.add("-1");
     replyTo.add("-1");
   }
   return replyTo;
 }
 public void testRetweetStatusAsJSON() throws Exception {
   // single Status
   HttpClientImpl http = new HttpClientImpl();
   Status status =
       new StatusJSONImpl(
           http.get("http://twitter4j.org/en/testcases/statuses/retweet/6010814202.json"), conf);
   Assert.assertEquals(new Date(1259078050000l), status.getCreatedAt());
   Assert.assertEquals(6011259778l, status.getId());
   Assert.assertEquals(null, status.getInReplyToScreenName());
   Assert.assertEquals(-1l, status.getInReplyToStatusId());
   Assert.assertEquals(-1, status.getInReplyToUserId());
   Assert.assertNull(status.getGeoLocation());
   Assert.assertEquals(
       "<a href=\"http://apiwiki.twitter.com/\" rel=\"nofollow\">API</a>", status.getSource());
   Assert.assertEquals(
       "RT @yusukey: この前取材受けた奴 -> 次世代のシステム環境を見据えたアプリケーションサーバー製品の選択 ITpro: http://special.nikkeibp.co.jp/ts/article/0iaa/104388/",
       status.getText());
   Assert.assertEquals(6358482, status.getUser().getId());
   Assert.assertTrue(status.isRetweet());
   assertDeserializedFormIsEqual(status);
 }
 public void testStatusAsJSON() throws Exception {
   // single Status
   HttpClientImpl http = new HttpClientImpl();
   List<Status> statuses =
       StatusJSONImpl.createStatusList(
           http.get("http://twitter4j.org/en/testcases/statuses/public_timeline.json"), conf);
   Status status = statuses.get(0);
   Assert.assertEquals(new Date(1259041785000l), status.getCreatedAt());
   Assert.assertEquals(6000554383l, status.getId());
   Assert.assertEquals("G_Shock22", status.getInReplyToScreenName());
   Assert.assertEquals(6000444309l, status.getInReplyToStatusId());
   Assert.assertEquals(20159829, status.getInReplyToUserId());
   Assert.assertNull(status.getGeoLocation());
   Assert.assertEquals("web", status.getSource());
   Assert.assertEquals(
       "@G_Shock22 I smelled a roast session coming when yu said that shyt about @2koolNicia lol....",
       status.getText());
   Assert.assertEquals(23459577, status.getUser().getId());
   Assert.assertFalse(status.isRetweet());
   assertDeserializedFormIsEqual(statuses);
 }
 @Override
 public View getView(final int position, final View convertView, final ViewGroup parent) {
   final View view =
       convertView != null ? convertView : mInflater.inflate(R.layout.activity_list_item, null);
   final Object tag = view.getTag();
   final ActivityViewHolder holder =
       tag instanceof ActivityViewHolder
           ? (ActivityViewHolder) tag
           : new ActivityViewHolder(view);
   if (!(tag instanceof ActivityViewHolder)) {
     view.setTag(holder);
   }
   holder.reset();
   holder.setTextSize(mTextSize);
   final twitter4j.Activity item = getItem(position);
   final Date created_at = item.getCreatedAt();
   if (created_at != null) {
     if (mShowAbsoluteTime) {
       holder.time.setText(formatSameDayTime(mContext, created_at.getTime()));
     } else {
       holder.time.setText(getRelativeTimeSpanString(created_at.getTime()));
     }
   }
   final User[] sources = item.getSources();
   final Status[] target_statuses = item.getTargetStatuses();
   final int sources_length = sources != null ? sources.length : 0;
   final int target_statuses_length = target_statuses != null ? target_statuses.length : 0;
   final Action action = item.getAction();
   holder.profile_image.setVisibility(mDisplayProfileImage ? View.VISIBLE : View.GONE);
   if (sources_length > 0) {
     final User first_source = sources[0];
     final Status[] target_objects = item.getTargetObjectStatuses();
     final String name = mDisplayName ? first_source.getName() : first_source.getScreenName();
     switch (action.getActionId()) {
       case Action.ACTION_FAVORITE:
         {
           if (target_statuses_length > 0) {
             final Status status = target_statuses[0];
             holder.text.setSingleLine(true);
             holder.text.setEllipsize(TruncateAt.END);
             holder.text.setText(status.getText());
           }
           if (sources_length == 1) {
             holder.title.setText(mContext.getString(R.string.activity_about_me_favorite, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_favorite_multi, name, sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
       case Action.ACTION_FOLLOW:
         {
           holder.text.setVisibility(View.GONE);
           if (sources_length == 1) {
             holder.title.setText(mContext.getString(R.string.activity_about_me_follow, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_follow_multi, name, sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
       case Action.ACTION_MENTION:
         {
           holder.title.setText(name);
           if (target_objects != null && target_objects.length > 0) {
             final Status status = target_objects[0];
             holder.text.setText(status.getText());
             if (status.getInReplyToStatusId() > 0 && status.getInReplyToScreenName() != null) {
               holder.reply_status.setVisibility(View.VISIBLE);
               holder.reply_status.setText(
                   mContext.getString(R.string.in_reply_to, status.getInReplyToScreenName()));
               holder.reply_status.setCompoundDrawablesWithIntrinsicBounds(
                   R.drawable.ic_indicator_reply, 0, 0, 0);
             }
           }
           setProfileImage(first_source.getProfileImageURL(), holder);
           break;
         }
       case Action.ACTION_REPLY:
         {
           holder.title.setText(name);
           if (target_statuses_length > 0) {
             final Status status = target_statuses[0];
             holder.text.setText(status.getText());
             if (status.getInReplyToStatusId() > 0 && status.getInReplyToScreenName() != null) {
               holder.reply_status.setVisibility(View.VISIBLE);
               holder.reply_status.setText(
                   mContext.getString(R.string.in_reply_to, status.getInReplyToScreenName()));
               holder.reply_status.setCompoundDrawablesWithIntrinsicBounds(
                   R.drawable.ic_indicator_reply, 0, 0, 0);
             }
           }
           setProfileImage(first_source.getProfileImageURL(), holder);
           break;
         }
       case Action.ACTION_RETWEET:
         {
           if (target_objects != null && target_objects.length > 0) {
             final Status status = target_objects[0];
             holder.text.setSingleLine(true);
             holder.text.setEllipsize(TruncateAt.END);
             holder.text.setText(status.getText());
           }
           if (sources_length == 1) {
             holder.title.setText(mContext.getString(R.string.activity_about_me_retweet, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_retweet_multi, name, sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
       case Action.ACTION_LIST_MEMBER_ADDED:
         {
           holder.text.setVisibility(View.GONE);
           if (sources_length == 1) {
             holder.title.setText(
                 mContext.getString(R.string.activity_about_me_list_member_added, name));
           } else {
             holder.title.setText(
                 mContext.getString(
                     R.string.activity_about_me_list_member_added_multi,
                     name,
                     sources_length - 1));
           }
           holder.activity_profile_image_container.setVisibility(
               mDisplayProfileImage ? View.VISIBLE : View.GONE);
           setUserProfileImages(sources, holder);
           break;
         }
     }
   }
   return view;
 }
Пример #7
0
  public static Record buildTweet(Schema schema, Status status) {
    GenericRecordBuilder builderTweet = new GenericRecordBuilder(schema);

    builderTweet.set("created_at", status.getCreatedAt().getTime());
    builderTweet.set("favorite_count", status.getFavoriteCount());
    builderTweet.set("favorited", status.isFavorited());
    builderTweet.set("id", status.getId());
    builderTweet.set("in_reply_to_screen_name", status.getInReplyToScreenName());
    if (status.getInReplyToStatusId() != -1)
      builderTweet.set("in_reply_to_status_id", status.getInReplyToStatusId());
    if (status.getInReplyToUserId() != -1)
      builderTweet.set("in_reply_to_user_id", status.getInReplyToUserId());
    builderTweet.set("lang", status.getLang());
    builderTweet.set("possibly_sensitive", status.isPossiblySensitive());
    builderTweet.set("retweet_count", status.getRetweetCount());
    builderTweet.set("retweeted", status.isRetweeted());
    builderTweet.set("source", status.getSource());
    builderTweet.set("text", status.getText());
    builderTweet.set("truncated", status.isTruncated());
    if (status.getWithheldInCountries() != null)
      builderTweet.set("withheld_in_countries", Arrays.asList(status.getWithheldInCountries()));
    if (status.getGeoLocation() != null)
      builderTweet.set(
          "coordinates",
          Arrays.asList(
              status.getGeoLocation().getLatitude(), status.getGeoLocation().getLongitude()));

    builderTweet.set("entities", buildEntities(schema.getField("entities").schema(), status));

    if (status.getPlace() != null)
      builderTweet.set(
          "place",
          buildPlace(schema.getField("place").schema().getTypes().get(1), status.getPlace()));

    User user = status.getUser();
    if (user != null && schema.getField("user") != null) {
      Schema schemaUser = schema.getField("user").schema();
      GenericRecordBuilder builderUser = new GenericRecordBuilder(schemaUser);
      builderUser.set("contributors_enabled", user.isContributorsEnabled());
      builderUser.set("created_at", user.getCreatedAt().getTime());
      builderUser.set("default_profile", user.isDefaultProfile());
      builderUser.set("default_profile_image", user.isDefaultProfileImage());
      builderUser.set("description", user.getDescription());
      builderUser.set(
          "entities",
          buildURLEntity(schemaUser.getField("entities").schema(), user.getURLEntity()));
      builderUser.set("favourites_count", user.getFavouritesCount());
      builderUser.set("followers_count", user.getFollowersCount());
      builderUser.set("friends_count", user.getFriendsCount());
      builderUser.set("geo_enabled", user.isGeoEnabled());
      builderUser.set("id", user.getId());
      builderUser.set("is_translator", user.isTranslator());
      builderUser.set("lang", user.getLang());
      builderUser.set("listed_count", user.getListedCount());
      builderUser.set("location", user.getLocation());
      builderUser.set("name", user.getName());
      builderUser.set("screen_name", user.getScreenName());
      builderUser.set("profile_background_color", user.getProfileBackgroundColor());
      builderUser.set("profile_background_image_url", user.getProfileBackgroundImageURL());
      builderUser.set(
          "profile_background_image_url_https", user.getProfileBackgroundImageUrlHttps());
      builderUser.set("profile_background_tile", user.isProfileBackgroundTiled());
      builderUser.set("profile_banner_url", user.getProfileBannerURL());
      builderUser.set("profile_image_url", user.getProfileImageURL());
      builderUser.set("profile_image_url_https", user.getProfileBackgroundImageUrlHttps());
      builderUser.set("profile_link_color", user.getProfileLinkColor());
      builderUser.set("profile_sidebar_border_color", user.getProfileSidebarBorderColor());
      builderUser.set("profile_sidebar_fill_color", user.getProfileSidebarFillColor());
      builderUser.set("profile_text_color", user.getProfileTextColor());
      builderUser.set("profile_use_background_image", user.isProfileUseBackgroundImage());
      builderUser.set("protected", user.isProtected());
      builderUser.set("show_all_inline_media", user.isShowAllInlineMedia());
      builderUser.set("statuses_count", user.getStatusesCount());
      builderUser.set("time_zone", user.getTimeZone());
      builderUser.set("url", user.getURL());
      builderUser.set("utc_offset", user.getUtcOffset());
      builderUser.set("verified", user.isVerified());
      if (user.getStatus() != null && schemaUser.getField("status") != null)
        builderUser.set(
            "status",
            buildTweet(schemaUser.getField("status").schema().getTypes().get(1), user.getStatus()));
      if (user.getWithheldInCountries() != null)
        builderUser.set("withheld_in_countries", Arrays.asList(user.getWithheldInCountries()));
      builderTweet.set("user", builderUser.build());
    }

    if (status.getQuotedStatus() != null && schema.getField("quoted_status") != null)
      builderTweet.set(
          "quoted_status",
          buildTweet(
              schema.getField("quoted_status").schema().getTypes().get(1),
              status.getQuotedStatus()));

    if (status.getRetweetedStatus() != null && schema.getField("retweeted_status") != null)
      builderTweet.set(
          "retweeted_status",
          buildTweet(
              schema.getField("retweeted_status").schema().getTypes().get(1),
              status.getRetweetedStatus()));

    return builderTweet.build();
  }