public static String getUserTimeline(List<String> ids) { Facebook facebook = FacebookUtil.getFacebookInstance(); int max_posts = 10; for (String key : ids) { boolean fileSave = false; String home = System.getProperty("user.home"); try { // write data into local file File file = new File(home + File.separator + "f_" + key.toLowerCase() + ".txt"); if (file.exists()) { log.info( "File " + home + File.separator + "f_" + key.toLowerCase() + ".txt" + " already exists"); file.delete(); log.info( "File " + home + File.separator + "f_" + key.toLowerCase() + ".txt" + " deleted"); } if (!file.exists()) { file.createNewFile(); log.info( "File " + home + File.separator + "f_" + key.toLowerCase() + ".txt" + " created"); } BufferedWriter writer = new BufferedWriter(new FileWriter(file)); User user = facebook.getUser(key, new Reading().fields("email")); System.out.println(" user " + user.getUsername()); ResponseList<Post> feeds = facebook.getPosts(key, new Reading().limit(max_posts)); // For all 25 feeds... for (int i = 0; i < feeds.size(); i++) { // Get post. Post post = feeds.get(i); // Get (string) message. String message = post.getMessage(); // Print out the message. System.out.println(message); // Get more stuff... PagableList<Comment> comments = post.getComments(); String date = post.getCreatedTime().toString(); String name = post.getFrom().getName(); String id = post.getId(); } } catch (FacebookException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (fileSave) log.info(home + File.separator + key + " .txt saved sucessfully"); else log.error("Failed to save " + home + File.separator + key + ".txt"); } } return "hello"; }
public static XContentBuilder toJson( Post post, String riverName, Map<String, List<EntityReference>> entities, Map<String, List<String>> mauiTopics, List<Map<String, String>> bayesianAnalyzedText) throws IOException { XContentBuilder out = XContentFactory.jsonBuilder().startObject(); out.field("PostId", post.getId()); out.field("PostLink", post.getLink() != null ? post.getLink().toString() : null); out.field("PostCreatedTime", post.getCreatedTime()); IdNameEntity idName = null; if ((idName = post.getFrom()) != null) { out.field("PostFromId", idName.getId()); out.field("PostFromName", idName.getName()); } if (post.getStatusType() != null) { out.field("PostStatusType", post.getStatusType()); } out.field("Post", post.getMessage()); if (entities != null) { if (entities.isEmpty()) { out.field("entities", "{}"); } else { out.startArray("entities"); for (Map.Entry<String, List<EntityReference>> entityEntry : entities.entrySet()) { out.startObject(); out.startArray(entityEntry.getKey()); for (EntityReference er : entityEntry.getValue()) { out.startObject(); out.field("entity-label", er.getEntityLabel()); out.field("entity-reference", er.getEntityReference()); out.field("entity-confidence", er.getConfidence()); out.startArray("entity-type"); for (String s : er.getEntityTypeList()) { out.startObject(); out.field("type", s); out.endObject(); } out.endArray(); out.endObject(); } out.endArray(); out.endObject(); } out.endArray(); } } if (mauiTopics != null) { if (mauiTopics.isEmpty()) { out.field("topics", "{}"); } else { out.startArray("topics"); out.startObject(); for (Map.Entry<String, List<String>> e : mauiTopics.entrySet()) { out.startArray(e.getKey()); for (String s : e.getValue()) { out.startObject(); out.field("text", s); out.endObject(); } out.endArray(); } out.endObject(); out.endArray(); } } if (bayesianAnalyzedText != null) { if (bayesianAnalyzedText.isEmpty()) { out.field("BayesianAnalysers", "{}"); } else { out.startArray("BayesianAnalysers"); out.startObject(); for (Map<String, String> m : bayesianAnalyzedText) { if (m == null || m.isEmpty()) { continue; } for (Map.Entry<String, String> e : m.entrySet()) { out.startArray(e.getKey()); out.startObject(); out.field("text", e.getValue()); out.endObject(); out.endArray(); } } out.endObject(); out.endArray(); } } if (riverName != null) { out.field("RiverName", riverName); } return out.endObject(); }