/** Unit Test ensuring some basic initialization properties being set. */ @Test public void testSearchReceivingMessageSourceInit() { final SearchReceivingMessageSource messageSource = new SearchReceivingMessageSource(new TwitterTemplate("test"), "foo"); messageSource.setComponentName("twitterSearchMessageSource"); final Object metadataStore = TestUtils.getPropertyValue(messageSource, "metadataStore"); final Object metadataKey = TestUtils.getPropertyValue(messageSource, "metadataKey"); assertNull(metadataStore); assertNotNull(metadataKey); messageSource.setBeanFactory(mock(BeanFactory.class)); messageSource.afterPropertiesSet(); final Object metadataStoreInitialized = TestUtils.getPropertyValue(messageSource, "metadataStore"); final Object metadataKeyInitialized = TestUtils.getPropertyValue(messageSource, "metadataKey"); assertNotNull(metadataStoreInitialized); assertTrue(metadataStoreInitialized instanceof SimpleMetadataStore); assertNotNull(metadataKeyInitialized); assertEquals("foo", metadataKeyInitialized); final Twitter twitter = TestUtils.getPropertyValue(messageSource, "twitter", Twitter.class); assertFalse(twitter.isAuthorized()); assertNotNull(twitter.userOperations()); }
/** * updates the users twitter-status to the tweets content. 1. reads the tweet with the given * tweetID from the database 2. checks if the related tweetGroup is still enabled and tweet wasn't * tweeted already 3. reads the users oAuthToken and oAuthTokenSecret from the database 4. updates * the users twitter status to the tweets tweetContent * * @param userID userID * @param tweetID tweetID */ public void run(int userID, int tweetID) { // read tweet from DB Tweet toTweet = DBConnector.getTweetByID(tweetID, userID); if (toTweet == null) { return; } // check if tweet was not tweeted already if (toTweet.tweeted) { return; } // check if tweetGroup is still enabled if (!DBConnector.isEnabledGroup(toTweet.groupID, userID)) { return; } // read userConfig (oAuthToken, tokenSecret) from DB String[] userConfig = DBConnector.getUserConfig(userID); String token = userConfig[1]; String tokenSecret = userConfig[2]; // Tweeting Twitter twitter = new TwitterTemplate(appID, appSecret, token, tokenSecret); // Add TweetContent String tweet = toTweet.content; TweetData tweetData = new TweetData(tweet); // add image if (toTweet.imageUrl != null) { try { Resource img = new UrlResource(toTweet.imageUrl); tweetData = tweetData.withMedia(img); } catch (MalformedURLException e) { tweetData = new TweetData(tweet + " " + toTweet.imageUrl); } } // add Geo-Locations if (toTweet.longitude != 0 || toTweet.latitude != 0) { System.out.println("long: " + toTweet.longitude); System.out.println("lat: " + toTweet.latitude); tweetData = tweetData.atLocation(toTweet.longitude, toTweet.latitude).displayCoordinates(true); } // update Status twitter.timelineOperations().updateStatus(tweetData); // update Tweet-Status in DB DBConnector.flagAsTweeted(tweetID, userID); }
/** Retweet a session tweet. */ @RequestMapping( value = "/events/{eventId}/sessions/{sessionId}/retweet", method = RequestMethod.POST) public @ResponseBody ResponseEntity<String> postSessionRetweet( @PathVariable Long eventId, @PathVariable Integer sessionId, @RequestParam Long tweetId) { twitter.timelineOperations().retweet(tweetId); return new ResponseEntity<String>(HttpStatus.OK); }
/** Post a tweet about a session. */ @RequestMapping( value = "/events/{eventId}/sessions/{sessionId}/tweets", method = RequestMethod.POST) public ResponseEntity<String> postSessionTweet( @PathVariable Long eventId, @PathVariable Integer sessionId, @RequestParam String status, Location currentLocation) { twitter.timelineOperations().updateStatus(status); return new ResponseEntity<String>(HttpStatus.OK); }
@Test public void test() { logger.debug("Running '{}'...", name.getMethodName()); con = usersConnectionRepository.createConnectionRepository("GeraldXv"); Connection<Twitter> twitter = con.findPrimaryConnection(Twitter.class); twitterApi = twitter.getApi(); Connection<Google> google = con.findPrimaryConnection(Google.class); googleApi = google.getApi(); System.out.println(twitterApi.friendOperations().getFriends().get(0).getName()); // System.out.println(googleApi.personOperations().getPerson("110377639084744464746").get); }
/** * Write a page of event tweet search results to the body of the response. The page number and * size may be provided by the client. If not specified, defaults to the first page of ten * results. */ @RequestMapping( value = "/events/{eventId}/tweets", method = RequestMethod.GET, produces = "application/json") public @ResponseBody SearchResults tweets( @PathVariable Long eventId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) { String searchString = eventRepository.findEventSearchString(eventId); return searchString != null && searchString.length() > 0 ? twitter.searchOperations().search(searchString, page, pageSize) : null; }
@RequestMapping("/result") public String hello(@RequestParam(defaultValue = "slawomir_krupa") String search, Model model) { // model.addAttribute("message","Hello" + userName); SearchResults searchResults = twitter.searchOperations().search(search); // List<String> tweets = List<Tweet> tweets = searchResults.getTweets(); // .stream() // .map(Tweet::getText) // .collect(Collectors.toList()); model.addAttribute("tweets", tweets); model.addAttribute("search", search); // model.addAttribute("message", text); return "resultPage"; }
@RequestMapping(value = "/twitter/followers", method = RequestMethod.GET) public String followers(Model model) { model.addAttribute("profiles", twitter.friendOperations().getFollowers()); return "twitter/friends"; }