Skip to content

Instantly share code, notes, and snippets.

@AlfredoCasado
Created January 21, 2014 18:34
Show Gist options
  • Save AlfredoCasado/8545531 to your computer and use it in GitHub Desktop.
Save AlfredoCasado/8545531 to your computer and use it in GitHub Desktop.
Groovy script that fetch all feeds with comments and 2nd level comments from a facebook page, using the library RestFB.
@Grapes(
@Grab(group='com.restfb', module='restfb', version='1.6.12')
)
import com.restfb.DefaultFacebookClient
import com.restfb.Parameter
import com.restfb.types.*
def token = "FACEBOOK_AUTH_TOKEN"
def page_id = "PAGE_ID"
this.facebook = new DefaultFacebookClient(token)
def topicsInPage = facebook.fetchConnection("${page_id}/feed", Post.class, Parameter.with("since", "1389984915")); // this operation allows "since" parameter
println "==============PAGE (${page_id})======================"
topicsInPage.data.each { topic ->
if (topic.message) println "Topic -> Body[${topic.message}] created at ${topic.createdTime.time / 1000}"
findComments(topic.id, " Comment ->")
}
def findComments(id, head) {
def comments = facebook.fetchConnection("${id}/comments", Comment.class, Parameter.with("since", "1390313487")) // in this operation "since" its not working
comments.data.each { comment ->
println "${head}Body[${comment.message}] created at ${comment.createdTime.time / 1000}"
findComments(comment.id, " Response ->")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment