diff --git a/MHealth_GroupFBScraper/.classpath b/MHealth_GroupFBScraper/.classpath new file mode 100644 index 0000000..57bc9f1 --- /dev/null +++ b/MHealth_GroupFBScraper/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/MHealth_GroupFBScraper/.gitignore b/MHealth_GroupFBScraper/.gitignore new file mode 100644 index 0000000..ae3c172 --- /dev/null +++ b/MHealth_GroupFBScraper/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/MHealth_GroupFBScraper/.project b/MHealth_GroupFBScraper/.project new file mode 100644 index 0000000..e1a62d6 --- /dev/null +++ b/MHealth_GroupFBScraper/.project @@ -0,0 +1,17 @@ + + + MHealth_GroupFBScraper + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/MHealth_GroupFBScraper/.settings/org.eclipse.jdt.core.prefs b/MHealth_GroupFBScraper/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..5caa538 --- /dev/null +++ b/MHealth_GroupFBScraper/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,13 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/MHealth_GroupFBScraper/src/Main.java b/MHealth_GroupFBScraper/src/Main.java new file mode 100644 index 0000000..9e63a0c --- /dev/null +++ b/MHealth_GroupFBScraper/src/Main.java @@ -0,0 +1,97 @@ +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Scanner; + +import com.opencsv.CSVWriter; +import com.restfb.*; +import com.restfb.types.Group; +import com.restfb.types.Post; + +/** + * TODO: + * Facebook authentication (no more temporary access codes) + * GUI + * + */ + +public class Main { + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + String accessToken = "EAALA0FZC8s14BAHoSr3OBZBh5OZBmtx5AZCTWyeLP8kKR3gNsaK6YWS1gWCcaKZAQNU7GWh3b8iQIEwcld0nQFIF7azfEw0ZChMxP05idWBhd2BQNZAuY9eLKxDuhjmEboTv4ZBz7hwQDe13CeXajnNOMU4A8zNZB5niZBiDHtMuapwdRXYAvwa9mLcM5KAXWYIG8Oo4QWMD6hogZDZD"; + + // Token expires daily - facebook auth needed for permanent one or app needs to login with facebook + Scanner input = new Scanner(System.in); + + FacebookClient fbClient = new DefaultFacebookClient(accessToken, Version.VERSION_3_1); + + Connection userGroups = fbClient.fetchConnection("me/groups", Group.class); + for(List page : userGroups) { + for(Group currGroup : page) { + //System.out.println("Do you want to get posts from "+currGroup.getName()+" ? Yes/NO"); // Eventually switch to GUI + //String response = input.nextLine(); + //if(response.equals("Yes")) { + // Removed above lines for testing (will need them in the future but not now since I'm only testing on one group) + if(currGroup.getId().equals("250530099176185")){ + Connection postFeed = fbClient.fetchConnection(currGroup.getId()+"/feed", Post.class, Parameter.with("fields","from,actions,message,likes,reactions")); + + writeCSVData(postFeed); + } + } + } + input.close(); + + + } + public static void writeCSVData(Connection postFeed) + { + // TODO - Finish + // File Name should be of format: Health Chat_Data Type_Group Name_Date Pulled.csv + /* Files needed: + * comments - headers: PostId, Id, UserId, UserName, CreatedTime, Message + * chat_feed - headers: Id, UserId, UserName, CreatedTime, Status Type, Message, Story, Link, Picture + * likes - headers: ObjectId, UserId, UserName + * reactions - headers: ObjectId, UserId, UserName, Type + * shares - headers: Id, UserId, UserName, CreatedTime, StatusType, Message, Story, Link, Picture + * + */ + try { + for(List getPosts : postFeed) { + //Create a list of posts from the post feed Y + for(Post currPost : getPosts) { + // Individual posts + // System.out.println(currPost.getFrom().getName()); + // System.out.println(currPost.getReactions().getData()); + // System.out.println(currPost.getLikes()); + // System.out.println("--> "+currPost.getMessage()); + // System.out.println("fb.com/"+currPost.getId()); + } + } + File file = new File(); + FileWriter outputfile = new FileWriter(file); + + // create CSVWriter object filewriter object as parameter + CSVWriter writer = new CSVWriter(outputfile); + + // create a List which contains String array + List data = new ArrayList(); + data.add(new String[] { "Name", "Class", "Marks" }); + data.add(new String[] { "Aman", "10", "620" }); + data.add(new String[] { "Suraj", "10", "630" }); + writer.writeAll(data); + + // closing writer connection + + writer.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + +}