List of usage examples for twitter4j User getId
long getId();
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
private void addFollowing(User twitterUser, boolean createNewUsers) { if (twitterUser == null) { return;//from www.j av a 2 s. c o m } IDs following; long cursor = -1; // look up person for twitter user and connect Person connectToPerson = getPersonForTwitterUser(twitterUser); do { try { following = twitterAPI.getFriendsIDs(twitterUser.getId(), cursor); log("Retrieving following with cursor: " + cursor, LogService.LOG_INFO); } catch (TwitterException e) { log("Could not get more following Users from twitter. (Cursor: " + cursor + "): " + e.getMessage(), LogService.LOG_DEBUG); break; } if (following == null) { return; } if (connectToPerson != null) { connectPersonsForTwitterUserIds(following.getIDs(), connectToPerson, true, createNewUsers); } // next cursor cursor = following.getNextCursor(); } while (following.hasNext()); }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
private void addFollower(User twitterUser, boolean createNewUsers) { if (twitterUser == null) { return;/*from ww w . j a va2s. c om*/ } int followersMax = 1000; int followersCount = twitterUser.getFollowersCount(); if (followersCount > followersMax) { // ignore users with to much followers log("Ignoring the " + followersCount + " Followers of " + twitterUser.getName()); return; } IDs followers; long cursor = -1; do { try { followers = twitterAPI.getFollowersIDs(twitterUser.getId(), cursor); log("Retrieving followers with cursor: " + cursor, LogService.LOG_INFO); } catch (TwitterException e) { log("Could not get more followers from twitter. (Cursor: " + cursor + "): " + e.getMessage(), LogService.LOG_DEBUG); break; } if (followers == null) { return; } // look up person for twitter user and connect Person connectToPerson = getPersonForTwitterUser(twitterUser); if (connectToPerson != null) { connectPersonsForTwitterUserIds(followers.getIDs(), connectToPerson, false, createNewUsers); } // next cursor cursor = followers.getNextCursor(); } while (followers.hasNext()); }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
/** * Looks up the person for this twitter user in the given dataSet and * returns it. If it does not already exist, the person will be created and * returned.// www .j ava 2s . c o m * * @param user * @return */ private Person createPersonFromTwitterUser(User user) { if (user == null) { return null; } Person person = getPersonForTwitterUser(user); String personIdent = createPersonIdentForTwitterUser(user); if (person == null) { // not previously created person = factory.createPerson(); // set name person.setName(user.getName()); // and add the person to the data set person = (Person) this.add(person, personIdent); } if (person == null) { // person could not be created return null; } // tag person person.metaTag(TwitterTags.TWITTER); // add web account String screenName = user.getScreenName(); if (screenName != null && !screenName.equals("")) { // TODO check for existing web account WebAccount webAccount = factory.createWebAccount(); webAccount.setUsername(screenName); webAccount.setCreated(user.getCreatedAt()); webAccount = (WebAccount) this.add(webAccount, screenName); if (webAccount != null) { webAccount.metaTag(TwitterTags.TWITTER); person.extend(webAccount); } } // add location String twitterLocation = user.getLocation(); if (twitterLocation != null && !twitterLocation.equals("")) { Location location = factory.createLocation(); location.setStringValue(twitterLocation); location = (Location) this.add(location, "uloc_" + user.getId()); if (location != null) { location.metaTag(TwitterTags.TWITTER); person.extend(location); } } // add website String twitterWebsite = user.getURL(); if (twitterWebsite != null) { WebSite website = factory.createWebSite(); website.setAdress(twitterWebsite.toString()); website = (WebSite) this.add(website); if (website != null) { website.metaTag(TwitterTags.TWITTER); person.extend(website); } } // add profile image String profileImageUrl = user.getBiggerProfileImageURL(); // add original res version if available if (screenName != null && source.isPropertyTrueElseDefault(TwitterProperties.LOAD_HIGHER_RES_PROFILE_IMAGE_PROPERTY, TwitterProperties.LOAD_HIGHER_RES_PROFILE_IMAGE_DEFAULT)) { if (user.getOriginalProfileImageURL() != null) { profileImageUrl = user.getOriginalProfileImageURL(); } } if (profileImageUrl != null) { // create image Image profileImage = person.attachImage(profileImageUrl); profileImage.tag(TwitterTags.TWITTER); profileImage.tag(TwitterTags.PROFILE_IMAGE); } // add latest status of user Status status = user.getStatus(); if (status != null && source.isPropertyTrue(TwitterProperties.ADD_STATUS_OF_PEOPLE_PROPERTY)) { createContentFromTweet(person, status); } return person; }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
private String createPersonIdentForTwitterUser(User user) { return "" + user.getId(); }
From source file:org.soluvas.buzz.twitter.TwitterUser.java
License:Apache License
/** * Clones attributes from Twitter4j's {@link User}. * @param src/*from w w w .java 2 s . co m*/ */ public TwitterUser(User src, int revId, DateTime fetchTime) { super(); this.revId = revId; this.fetchTime = fetchTime; id = src.getId(); name = src.getName(); screenName = src.getScreenName(); location = src.getLocation(); description = src.getDescription(); contributorsEnabled = src.isContributorsEnabled(); profileImageUrl = src.getProfileImageURL(); biggerProfileImageUrl = src.getBiggerProfileImageURL(); miniProfileImageUrl = src.getMiniProfileImageURL(); originalProfileImageUrl = src.getOriginalProfileImageURL(); profileImageUrlHttps = src.getProfileImageURLHttps(); biggerProfileImageUrlHttps = src.getBiggerProfileImageURLHttps(); miniProfileImageUrlHttps = src.getMiniProfileImageURLHttps(); originalProfileImageUrlHttps = src.getOriginalProfileImageURLHttps(); url = src.getURL(); protectedState = src.isProtected(); followersCount = src.getFollowersCount(); status = src.getStatus(); profileBackgroundColor = src.getProfileBackgroundColor(); profileTextColor = src.getProfileTextColor(); profileLinkColor = src.getProfileLinkColor(); profileSidebarFillColor = src.getProfileSidebarFillColor(); profileSidebarBorderColor = src.getProfileSidebarBorderColor(); profileUseBackgroundImage = src.isProfileUseBackgroundImage(); showAllInlineMedia = src.isShowAllInlineMedia(); friendsCount = src.getFriendsCount(); createdAt = new DateTime(src.getCreatedAt()); favouritesCount = src.getFavouritesCount(); utcOffset = src.getUtcOffset(); timeZone = src.getTimeZone(); profileBackgroundImageUrl = src.getProfileBackgroundImageURL(); profileBackgroundImageUrlHttps = src.getProfileBackgroundImageUrlHttps(); profileBannerUrl = src.getProfileBannerURL(); profileBannerRetinaUrl = src.getProfileBannerRetinaURL(); profileBannerIpadUrl = src.getProfileBannerIPadURL(); profileBannerIpadRetinaUrl = src.getProfileBannerIPadRetinaURL(); profileBannerMobileUrl = src.getProfileBannerMobileURL(); profileBannerMobileRetinaUrl = src.getProfileBannerMobileRetinaURL(); profileBackgroundTiled = src.isProfileBackgroundTiled(); lang = src.getLang(); statusesCount = src.getStatusesCount(); geoEnabled = src.isGeoEnabled(); verified = src.isVerified(); translator = src.isTranslator(); listedCount = src.getListedCount(); followRequestSent = src.isFollowRequestSent(); }
From source file:org.springframework.social.showcase.twitter.connect.TwitterApiAdapter.java
License:Apache License
@Override public void setConnectionValues(Twitter api, ConnectionValues values) { try {/*from w w w . j a va 2 s . com*/ User user = api.verifyCredentials(); values.setProviderUserId(Long.toString(user.getId())); values.setDisplayName("@" + user.getScreenName()); values.setProfileUrl("http://twitter.com/" + user.getScreenName()); values.setImageUrl(user.getProfileImageURL()); } catch (TwitterException e) { } }
From source file:org.tweetalib.android.model.TwitterDirectMessage.java
License:Apache License
public TwitterDirectMessage(DirectMessage message, User otherUser) { mId = message.getId();/*w w w. j av a 2s.com*/ mText = message.getText(); mStatusFullMarkup = TwitterUtil.getStatusMarkup(mText, message.getMediaEntities(), message.getURLEntities()); mTextSpanned = URLSpanNoUnderline .stripUnderlines(Html.fromHtml(mStatusFullMarkup.replace("\n", "<br/>") + " ")); mCreatedAt = message.getCreatedAt(); mOtherUserId = otherUser.getId(); mRecipientUserId = message.getRecipientId(); mOtherUserScreenName = otherUser.getScreenName(); mOtherUserName = otherUser.getName(); mOtherUserProfileImageOriginalUrl = otherUser.getOriginalProfileImageURL(); mOtherUserProfileImageMiniUrl = otherUser.getMiniProfileImageURL(); mOtherUserProfileImageNormalUrl = otherUser.getProfileImageURL(); mOtherUserProfileImageBiggerUrl = otherUser.getBiggerProfileImageURL(); TwitterUser sender = new TwitterUser(message.getSender()); mSenderProfileImageOriginalUrl = sender.getProfileImageUrlOriginal(); mSenderProfileImageMiniUrl = sender.getProfileImageUrlMini(); mSenderProfileImageNormalUrl = sender.getProfileImageUrlNormal(); mSenderProfileImageBiggerUrl = sender.getProfileImageUrlBigger(); mMessageType = mRecipientUserId == mOtherUserId ? MessageType.SENT : MessageType.RECEIVED; }
From source file:org.tweetalib.android.model.TwitterStatus.java
License:Apache License
public TwitterStatus(Status status) { User statusUser = status.getUser(); mCreatedAt = status.getCreatedAt();/*from w w w.j ava 2s . co m*/ mId = status.getId(); if (status.getInReplyToStatusId() != -1) { mInReplyToStatusId = status.getInReplyToStatusId(); } if (status.getInReplyToUserId() != -1) { mInReplyToUserId = status.getInReplyToUserId(); } mInReplyToUserScreenName = status.getInReplyToScreenName(); mIsFavorited = status.isFavorited(); mIsRetweet = status.isRetweet(); mIsRetweetedByMe = status.isRetweetedByMe(); mSource = TwitterUtil.stripMarkup(status.getSource()); if (statusUser != null) { mUserId = statusUser.getId(); mUserName = statusUser.getName(); mUserScreenName = statusUser.getScreenName(); } mMediaEntity = TwitterMediaEntity.createMediaEntity(status); boolean useDefaultAuthor = true; if (mIsRetweet) { if (status.getRetweetedStatus() != null && status.getRetweetedStatus().getUser() != null) { SetProfileImagesFromUser(new TwitterUser(status.getRetweetedStatus().getUser())); } mOriginalRetweetId = status.getRetweetedStatus().getId(); // You'd think this check wasn't necessary, but apparently not... UserMentionEntity[] userMentions = status.getUserMentionEntities(); if (userMentions != null && userMentions.length > 0) { useDefaultAuthor = false; UserMentionEntity authorMentionEntity = status.getUserMentionEntities()[0]; mAuthorId = authorMentionEntity.getId(); mAuthorName = authorMentionEntity.getName(); mAuthorScreenName = authorMentionEntity.getScreenName(); Status retweetedStatus = status.getRetweetedStatus(); mStatus = retweetedStatus.getText(); setStatusMarkup(retweetedStatus); mRetweetCount = retweetedStatus.getRetweetCount(); mUserMentions = TwitterUtil.getUserMentions(retweetedStatus.getUserMentionEntities()); mIsRetweetedByMe = retweetedStatus.isRetweetedByMe(); } } else { if (statusUser != null) { SetProfileImagesFromUser(new TwitterUser(statusUser)); } } if (useDefaultAuthor) { if (statusUser != null) { mAuthorId = statusUser.getId(); } mStatus = status.getText(); setStatusMarkup(status); mRetweetCount = status.getRetweetCount(); mUserMentions = TwitterUtil.getUserMentions(status.getUserMentionEntities()); } /* * if (status.getId() == 171546910249852928L) { mStatus = * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?" * ; mStatusMarkup = * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?" * ; mAuthorScreenName = "emmarclarke"; mStatusMarkup = mStatus; } else * if (status.getId() == 171444098698457089L) { mStatus = * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?" * ; mStatusMarkup = * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?" * ; mStatusMarkup = mStatus; } */ }
From source file:org.tweetalib.android.model.TwitterUser.java
License:Apache License
public TwitterUser(User user) { mId = user.getId(); mScreenName = user.getScreenName();//w ww . j a va2s . co m mName = user.getName(); mDescription = user.getDescription(); ArrayList<URLEntity> urlEntityArrayList = new ArrayList<URLEntity>(); if (user.getDescriptionURLEntities() != null) { urlEntityArrayList = new ArrayList<URLEntity>(Arrays.asList(user.getDescriptionURLEntities())); } if (user.getURL() != null) { mUrl = user.getURL(); urlEntityArrayList.add(user.getURLEntity()); } mUrlEntities = urlEntityArrayList.toArray(new URLEntity[urlEntityArrayList.size()]); if (user.getLocation() != null && !user.getLocation().equals("")) { mLocation = user.getLocation(); } if (user.getOriginalProfileImageURLHttps() != null) { mProfileImageUrlOriginal = user.getOriginalProfileImageURLHttps(); } if (user.getBiggerProfileImageURLHttps() != null) { mProfileImageUrlBigger = user.getBiggerProfileImageURLHttps(); } if (user.getProfileImageURLHttps() != null) { mProfileImageUrlNormal = user.getProfileImageURLHttps(); } if (user.getMiniProfileImageURLHttps() != null) { mProfileImageUrlMini = user.getMiniProfileImageURLHttps(); } mStatusesCount = user.getStatusesCount(); mFriendsCount = user.getFriendsCount(); mFollowersCount = user.getFollowersCount(); mFavoritesCount = user.getFavouritesCount(); mListedCount = user.getListedCount(); mVerified = user.isVerified(); mProtected = user.isProtected(); mSocialNetType = SocialNetConstant.Type.Twitter; }
From source file:org.tweetalib.android.TwitterFetchUser.java
License:Apache License
public void setUser(User user, boolean forceUpdate) { Long userId = Long.valueOf(user.getId()); TwitterUser twitterUser = new TwitterUser(user); if (forceUpdate || !mUserIdHashMap.containsKey(userId)) { mUserIdHashMap.put(userId, twitterUser); }/*from w w w . ja v a2 s. c o m*/ if (forceUpdate || !mUserIdHashMap.containsKey(twitterUser.getScreenName())) { mUserScreenNameHashMap.put(twitterUser.getScreenName(), twitterUser); } }