Skip to content

Instantly share code, notes, and snippets.

@arsduo
Created May 29, 2011 16:25
Show Gist options
  • Save arsduo/997914 to your computer and use it in GitHub Desktop.
Save arsduo/997914 to your computer and use it in GitHub Desktop.
Euruko demo code (Koala & Facebook)
# demo from Euruko lightning talk 2011
# links:
# * http://github.com/arsduo/koala (code/wiki documentation)
# * http://oauth.twoalex.com (easy access tokens)
# * http://developers.facebook.com/docs/coreconcepts/ (FB docs)
# the person I hang out with most
people = g.fql_query("select tagged_uids from checkin where author_uid = me()")
bestfriend = people.collect {|c| c["tagged_uids"]}.flatten.group_by {|u| u}.values.max_by(&:length).first
Koala::Facebook::GraphAPI.batch do
g.get_object(bestfriend, {}, :batch_args => {:name => "friend"})
g.put_wall_post("Calculated all my check-ins for this #euruko demo. Turns out I spend most of my time with {result=friend:$.name}!")
end
# the people who've commented on my posts recently
# you can use the limit argument to expand/contract the # of results
commenters = g.rest_call("fql.multiquery", :queries => {
:query1 => "select post_id from stream where source_id = me()",
:query2 => "select fromid from comment where post_id in (select post_id from #query1)",
:query3 => "select uid, name from user where uid in (select fromid from #query2)"
}.to_json)
commenters.last["fql_result_set"].collect {|u| u["name"]}
@arsduo
Copy link
Author

arsduo commented May 29, 2011

Forgot to mention -- the Batch API call (line 10) is part of Koala 1.1.0, which isn't out yet. It's in the master branch, so you can pull from there, or download the RC when it comes out in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment