Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Initial Commit
  • Loading branch information
Jackie committed Jan 16, 2019
0 parents commit c337fcb
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
8 changes: 8 additions & 0 deletions MHealth_GroupFBScraper/.classpath
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="C:/Users/Jackie/Downloads/restfb-2.15.0/restfb-2.15.0.jar"/>
<classpathentry kind="lib" path="C:/Users/Jackie/Downloads/opencsv-4.3.2.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions MHealth_GroupFBScraper/.gitignore
@@ -0,0 +1 @@
/bin/
17 changes: 17 additions & 0 deletions MHealth_GroupFBScraper/.project
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MHealth_GroupFBScraper</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
13 changes: 13 additions & 0 deletions 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
97 changes: 97 additions & 0 deletions 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<Group> userGroups = fbClient.fetchConnection("me/groups", Group.class);
for(List<Group> 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<Post> 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<Post> 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<Post> 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<String[]> data = new ArrayList<String[]>();
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();
}
}

}

0 comments on commit c337fcb

Please sign in to comment.