public static JSONObject user2json(User user) throws IOException { String jsonstring = TwitterObjectFactory.getRawJSON(user); JSONObject json = new JSONObject(jsonstring); json.put("retrieval_date", AbstractObjectEntry.utcFormatter.print(System.currentTimeMillis())); Object status = json.remove("status"); // we don't need to store the latest status update in the user dump // TODO: store the latest status in our message database return json; }
/** * Returns a raw JSON form of the provided object.<br> * Note that raw JSON forms can be retrieved only from the same thread invoked the last method call and will become inaccessible once another method call * * @param obj target object to retrieve JSON * @return raw JSON * @since Twitter4J 2.1.7 */ public static String getRawJSON(Object obj) { return TwitterObjectFactory.getRawJSON(obj); }
@Override public void onStatus(Status tweet) { String jsonTweet = TwitterObjectFactory.getRawJSON(tweet); inputQ.add(jsonTweet); }
@Override public void onStatus(Status status) { String jsonTweet = TwitterObjectFactory.getRawJSON(status); inputQ.add(jsonTweet); }
public void onStatus(Status status) { injectTwitterMessage(TwitterObjectFactory.getRawJSON(status)); }
public void onStatus(Status status) { injectTwitterMessage(TwitterObjectFactory.getRawJSON(status)); }
public void onStatus(long forUser, Status status) { injectTwitterMessage(TwitterObjectFactory.getRawJSON(status)); }
@Override public void onStatus(Status status) { String s = "{\"a\" : [{\"user\": \"" + status.getUser().getName() + "\", \"text\":\"" + status.getText() + "\"}]}"; // TODO uncomment again // // try { // System.out.println(s); // parser.parse(IOUtils.toInputStream(s, "UTF-8"), stp); // } catch (IOException e) { // e.printStackTrace(); // } System.out.println("============================"); System.out.println(status.getUser().getName() + " : " + status.getText()); System.out.println(TwitterObjectFactory.getRawJSON(status)); System.out.println("============================"); }
@Override public void onStatus(Status status) { String s = "{\"a\" : [{\"user\": \"" + status.getUser().getName() + "\", \"text\":\"" + status.getText() + "\"}]}"; // TODO uncomment again // // try { // System.out.println(s); // parser.parse(IOUtils.toInputStream(s, "UTF-8"), stp); // } catch (IOException e) { // e.printStackTrace(); // } System.out.println("============================"); System.out.println(status.getUser().getName() + " : " + status.getText()); System.out.println(TwitterObjectFactory.getRawJSON(status)); System.out.println("============================"); }
@Override public IRawRecord<char[]> next() throws IOException, InterruptedException { if (result == null || nextTweetIndex >= result.getTweets().size()) { Thread.sleep(1000 * requestInterval); query.setSinceId(lastTweetIdReceived); try { result = twitter.search(query); } catch (TwitterException e) { throw HyracksDataException.create(e); } nextTweetIndex = 0; } if (result != null && !result.getTweets().isEmpty()) { List<Status> tw = result.getTweets(); Status tweet = tw.get(nextTweetIndex++); if (lastTweetIdReceived < tweet.getId()) { lastTweetIdReceived = tweet.getId(); } String jsonTweet = TwitterObjectFactory.getRawJSON(tweet); // transform tweet obj to json record.set(jsonTweet); return record; } else { return null; } }