/*package*/ static ResponseList<User> createUserList(HttpResponse res, Configuration conf) throws FacebookException { try { if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.clearThreadLocalMap(); } JSONObject json = res.asJSONObject(); JSONArray list = json.getJSONArray("data"); final int size = list.length(); ResponseList<User> users = new ResponseListImpl<User>(size, json); for (int i = 0; i < size; i++) { JSONObject userJSONObject = list.getJSONObject(i); User user = new UserJSONImpl(userJSONObject); if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(user, userJSONObject); } users.add(user); } if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(users, list); } return users; } catch (JSONException jsone) { throw new FacebookException(jsone); } }
/*package*/ static ResponseList<Message> createMessageList(HttpResponse res, Configuration conf) throws FacebookException { try { if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.clearThreadLocalMap(); } JSONObject json = res.asJSONObject(); JSONArray list = json.getJSONArray("data"); int size = list.length(); ResponseList<Message> messages = new ResponseListImpl<Message>(size, json); for (int i = 0; i < size; i++) { Message message = new MessageJSONImpl(list.getJSONObject(i)); messages.add(message); } if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(messages, json); } return messages; } catch (JSONException jsone) { throw new FacebookException(jsone); } }
/*package*/ static ResponseList<Checkin> createCheckinList(HttpResponse res, Configuration conf) throws FacebookException { try { if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.clearThreadLocalMap(); } JSONObject json = res.asJSONObject(); JSONArray list = json.getJSONArray("data"); int size = list.length(); ResponseList<Checkin> checkins = new ResponseListImpl<Checkin>(size, json); for (int i = 0; i < size; i++) { Checkin checkin = new CheckinJSONImpl(list.getJSONObject(i)); checkins.add(checkin); } if (conf.isJSONStoreEnabled()) { DataObjectFactoryUtil.registerJSONObject(checkins, json); } return checkins; } catch (JSONException jsone) { throw new FacebookException(jsone); } }
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"; }