List of usage examples for twitter4j User getId
long getId();
From source file:aic2013.common.entities.TwitterUser.java
public TwitterUser(User user) { id = user.getId(); name = user.getName();//from ww w. j a v a 2 s . c om screenName = user.getScreenName(); lang = user.getLang(); followersCount = user.getFollowersCount(); statusesCount = user.getStatusesCount(); friendsCount = user.getFriendsCount(); favouritesCount = user.getFavouritesCount(); listedCount = user.getListedCount(); }
From source file:aic2013.extractor.entities.TwitterUser.java
public TwitterUser(User user) { id = user.getId(); name = user.getName();/*from w w w.j a v a2s . c o m*/ screenName = user.getScreenName(); language = user.getLang(); followersCount = user.getFollowersCount(); statusesCount = user.getStatusesCount(); friendsCount = user.getFriendsCount(); favouritesCount = user.getFavouritesCount(); listedCount = user.getListedCount(); }
From source file:aic2013.extractor.TwitterExtractor.java
public static void main(String[] args) throws Exception { EntityManagerFactory emf = null;/*from ww w. j a v a 2 s . c o m*/ MongoClient mongoClient = null; Twitter twitter = null; Neo4jConnection neo4j = null; try { // Database configuration Properties prop = new Properties(); prop.load(new FileInputStream("hibernate.properties")); // prop.load(TwitterExtractor.class.getClassLoader().getResourceAsStream("hibernate.properties")); emf = Persistence.createEntityManagerFactory("twitterdb", prop); final String mongoServer = "localhost"; mongoClient = new MongoClient(mongoServer); twitter = TwitterFactory.getSingleton(); // final String neo4jJdbc = "jdbc:neo4j:ec2-54-217-131-208.eu-west-1.compute.amazonaws.com:7474"; final String neo4jJdbc = "jdbc:neo4j://localhost:7474"; neo4j = new Driver().connect(neo4jJdbc, new Properties()); neo4j.setAutoCommit(true);//false); final TwitterDataAccess twitterDataAccess = new TwitterDataAccess(twitter); final MongoDataAccess mongoDataAccess = new MongoDataAccess(mongoClient); final Neo4jService neo4jService = new Neo4jService(neo4j); final EntityManager em = emf.createEntityManager(); final UserDataAccess userDataAcces = new UserDataAccess(em); final TopicExtractionCoordinator extractionCoordinator = new TopicExtractionCoordinatorImpl(); // final ConcurrentLinkedQueue<E> final UserService userService = new UserService(em); final Processor<Status> mongoProcessor = new Processor<Status>() { @Override public void process(final Status status) { final TwitterUser user = new TwitterUser(status.getUser()); userService.persist(user); neo4jService.transactional(new Neo4jUnitOfWork() { @Override public void process() throws SQLException { neo4jService.createPersonIfAbsent(user); // HashtagEntity[] topics = // status.getHashtagEntities(); Status originalStatus = status; if (status.isRetweet()) { originalStatus = status.getRetweetedStatus(); } extractionCoordinator.doExtraction(originalStatus, new TopicExtractionCallback() { @Override public void handleExtractionResult(Set<Topic> extractedTopics) { /* TODO: comment out outputs */ // System.out.println(status.getText()); // for (Topic t : extractedTopics) { // System.out.println(t.getName()); // } try { /* add hash tags to topics */ for (HashtagEntity tag : status.getHashtagEntities()) { extractedTopics.add(new Topic(new String[] { tag.getText() })); } for (Topic topic : extractedTopics) { neo4jService.createTopicIfAbsent(topic); if (status.isRetweet()) { neo4jService.createRelationIfAbsent("RETWEETS", user, topic); } else { neo4jService.createRelationIfAbsent("TWEETS", user, topic); } } } catch (SQLException e) { throw new RuntimeException(e); } } @Override public void handleExtractionError(ExtractionException e) { throw new RuntimeException(e); } }); } }); } }; final Processor<TwitterUser> userProcessor = new Processor<TwitterUser>() { @Override public void process(final TwitterUser user) { try { twitterDataAccess.forAllFollowers(user, new Processor<User>() { @Override public void process(User u) { final TwitterUser follower = em.find(TwitterUser.class, u.getId()); if (follower != null) { neo4jService.transactional(new Neo4jUnitOfWork() { @Override public void process() throws SQLException { neo4jService.createUniqueRelation("FOLLOWS", user, follower); } }); } } }); } catch (Exception ex) { throw new RuntimeException(ex); } } }; // invoke the processor for every entry in mongo mongoDataAccess.forAll(mongoProcessor); extractionCoordinator.awaitTermination(-1, TimeUnit.SECONDS); // invoke the processor for every entry in the rdbms // userDataAcces.forAll(userProcessor); } finally { if (emf != null && emf.isOpen()) { emf.close(); } if (mongoClient != null) { mongoClient.close(); } if (twitter != null) { twitter.shutdown(); } if (neo4j != null) { neo4j.close(); } } }
From source file:au.net.moon.tUtils.TUser.java
License:Open Source License
/** * Create a user object from a twitter4j user. * //from www.j a v a 2s. co m * @param twitterUser * a twitter4j user object */ public TUser(twitter4j.User twitterUser) { id = twitterUser.getId(); name = twitterUser.getName(); screenName = twitterUser.getScreenName(); location = twitterUser.getLocation(); description = twitterUser.getDescription(); if (twitterUser.getProfileImageURL() != null) { profileImageUrl = twitterUser.getProfileImageURL().toString(); } else { profileImageUrl = ""; } if (twitterUser.getURL() != null) { url = twitterUser.getURL().toString(); } else { url = ""; } createdAt = twitterUser.getCreatedAt(); isProtected = twitterUser.isProtected(); followersCount = twitterUser.getFollowersCount(); // Not interested in users latest tweet, so just leave blank status = ""; profileBackgroundColor = twitterUser.getProfileBackgroundColor(); profileTextColor = twitterUser.getProfileTextColor(); profileLinkColor = twitterUser.getProfileLinkColor(); profileSidebarFillColor = twitterUser.getProfileSidebarFillColor(); profileSidebarBorderColor = twitterUser.getProfileSidebarBorderColor(); friendsCount = twitterUser.getFriendsCount(); favouritesCount = twitterUser.getFavouritesCount(); utcOffset = twitterUser.getUtcOffset(); timeZone = twitterUser.getTimeZone(); if (twitterUser.getOriginalProfileImageURL() != null) { profileBackgroundImageUrl = twitterUser.getOriginalProfileImageURL().toString(); } else { profileBackgroundImageUrl = ""; } isProfileBackgroundTiled = twitterUser.isProfileBackgroundTiled(); statusesCount = twitterUser.getStatusesCount(); isGeoEnabled = twitterUser.isGeoEnabled(); isVerified = twitterUser.isVerified(); // isFollowing = twitterUser.isFollowing(); isContributorsEnabled = twitterUser.isContributorsEnabled(); isProfileUseBackgroundImage = twitterUser.isProfileUseBackgroundImage(); isShowAllInLineMedia = twitterUser.isShowAllInlineMedia(); lang = twitterUser.getLang(); isTranslator = twitterUser.isTranslator(); listedCount = twitterUser.getListedCount(); isFollowRequestSent = twitterUser.isFollowRequestSent(); // TODO: Need to pass in the searchAPI id if I have it. searchAPI_userID = ""; }
From source file:be.ugent.tiwi.sleroux.newsrec.newsreclib.twitter.UserHelper.java
License:Apache License
public long getUserId(String screenName) throws TwitterException { User user = twitter.showUser(screenName); return user.getId(); }
From source file:be.ugent.tiwi.sleroux.newsrec.twittertest.App.java
public static void main(String[] args) throws TwitterException { Twitter twitter = TwitterFactory.getSingleton(); AccessToken accessToken = new AccessToken("2369203675-1Pk99eotzhCznmIgr3iXb670DpsEVQCANuoBHRs", "6ua72cabIzcFsBgE15RVzULeKT44TnIrOIaf9chY9dlWe"); twitter.setOAuthConsumer("tQjT8XvB7OPNTl8qdhchDo3J2", "FXWVS3OEW7omiUDSLpET0aRInoUumGPWRxOVyk7GrhiwcfLBnV"); twitter.setOAuthAccessToken(accessToken); User user = twitter.showUser("billclinton"); System.out.println("id=" + user.getId()); StreamReaderService srs = new StreamReaderService(); srs.readTwitterFeed();// w w w . jav a 2s . c o m }
From source file:br.com.porcelli.hornetq.integration.twitter.support.TweetMessageConverterSupport.java
License:Apache License
private static void buildUserData(final String prefix, final User user, ServerMessage msg) { msg.putStringProperty(prefix + TwitterConstants.KEY_USER_ID, read(user.getId())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_NAME, read(user.getName())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_SCREEN_NAME, read(user.getScreenName())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_LOCATION, read(user.getLocation())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_DESCRIPTION, read(user.getDescription())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_PROFILE_IMAGE_URL, read(user.getProfileImageURL())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_URL, read(user.getURL())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_LANG, read(user.getLang())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_PROTECTED, read(user.isProtected())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_FOLLOWERS_COUNT, read(user.getFollowersCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_FRIENDS_COUNT, read(user.getFriendsCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_CREATED_AT, read(user.getCreatedAt())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_FAVOURITES_COUNT, read(user.getFavouritesCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_UTC_OFFSET, read(user.getUtcOffset())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_TIME_ZONE, read(user.getTimeZone())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_STATUSES_COUNT, read(user.getStatusesCount())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_VERIFIED, read(user.isVerified())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_CONTRIBUTORS_ENABLED, read(user.isContributorsEnabled())); msg.putStringProperty(prefix + TwitterConstants.KEY_USER_GEO_ENABLED, read(user.isGeoEnabled())); }
From source file:com.ahuralab.mozaic.db.Message.java
License:Open Source License
public static Message create(Status status) { User user = status.getUser(); return new Message(status.getText(), status.getCreatedAt(), status.getRetweetCount(), user.getId(), user.getName(), user.getScreenName(), user.getLocation(), user.getDescription(), user.getProfileImageURL(), status.getId(), 0, 0, user.getFollowersCount(), user.getStatusesCount()); }
From source file:com.anshul.HomeServlet.java
License:Open Source License
private void statusCheck(Twitter twitter, HttpServletRequest req, HttpServletResponse resp) throws IOException, TwitterException { User user = twitter.verifyCredentials(); String username = user.getName(); String latestTweet = user.getStatus().getText(); TweetWrapper tweetWrapper = TweetWrapper.feel(latestTweet); String emotion = tweetWrapper.getStrongestEmotion(); DatastoreService datastore = DatastoreServiceFactory.getDatastoreService(); Query query = new Query("Station"); query.setFilter(FilterOperator.EQUAL.of("mood", emotion)); List<Entity> stations = datastore.prepare(query).asList(FetchOptions.Builder.withLimit(1)); Entity station = stations.get(0); req.getSession().setAttribute("user", username); req.getSession().setAttribute("userId", user.getId()); req.getSession().setAttribute("latestTweet", latestTweet); req.getSession().setAttribute("emotion", emotion); req.getSession().setAttribute("stationName", station.getProperty("name")); req.getSession().setAttribute("url", station.getProperty("url")); req.getSession().setAttribute("profileImage", user.getBiggerProfileImageURL()); req.removeAttribute("oauth_token"); req.removeAttribute("oauth_verifier"); resp.sendRedirect("login.jsp"); }
From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java
License:Apache License
public void sendUrlStatistics() { try {//from ww w . j a va 2 s . c o m Twitter twitter = getTwitterClient(); UserService userService = ServiceFactory.newInstance().createUserService(); for (User user : twitter.getFriendsStatuses()) { com.appspot.bitlyminous.entity.User entity = userService.getUserByScreenName(user.getScreenName()); List<Url> urls = entity.getUrls(); twitter.sendDirectMessage(user.getId(), buildUrlStatisticsStatus(urls)); } } catch (Exception e) { throw new ServiceException(e); } }