开发者

Facebook FQL Multi.Query: Joining Result Sets

I'm using Facebook's fql.multiquery for a number of different things and I'm getting the results back - just as the doctor ordered. But I can't seem to wrap my head around how to join the results so I can give them back to the user in the way I want.

I'm using HTTParty to call this:

  checkin_query = {
    "user_checkins" => "SELECT timestamp, coords, tagged_uids, page_id, post_id, checkin_id, message FROM checkin WHERE author_uid= me()",
    "location_names" => "SELECT name FROM page WHERE page_id IN (SELECT page_id FROM #user_checkins)",
    "friends_with" => "SELECT uid, name, pic_square FROM user WHERE uid IN (select tagged_uids FROM #user_checkins)"
  }

  params = {:queries => checkin_query.to_json, :access_token => user.token, :format => :json}
  @checkin_info = HTTParty.get "https://api.facebook.com/method/fql.multiquery", :query => params
开发者_StackOverflow

Which gives me what I want... but it's in 3 separate arrays/hashes (?) and for some reason, my brain isn't coming to a conclusion on how to deal with it.

So basically if I wanted to show the user "OK dude, you were at *LOCATION_NAME* with these people: *FRIENDS_WITH*

How can I take those 3 separate result sets and match everything up? Is there a way to include something from a previous query to call back and match it so I can display everything? Some check-ins have no tagged_uids, so obviously just doing it in order won't work when it comes to the friends they're with.

Google searches have shown me SQL's JOIN (which seems like it may be a solution) - but isn't available in FQL.


I have no experience with either FQL or HTTParty so I might have this completely wrong.

I tend to format the sql as follows:

checkin_query = {
  "user_checkins" => "
    SELECT tagged_uids, page_id
    FROM checkin
    WHERE author_uid = me()
  ",

  "location_names" => "
    SELECT name
    FROM page
    WHERE page_id IN (
      SELECT page_id
      FROM #user_checkins
    )
  ",

  "friends_with" => "
    SELECT name
    FROM user
    WHERE uid IN (
      SELECT tagged_uids
      FROM #user_checkins
    )
  "
}

location_names and friends_with are probably returned as arrays of hashes:

"friends_with" => [{:name => 'John'}, {:name => 'Sue'}]

Not sure what HTTParty returns, but if it is hashes of arrays of hashes you might try:

puts "OK dude, you were at #{ @checkin_info[:location_names].map { |e| e.values } } with these people: #{ @checkin_info[:friends_with].map { |e| e.values } }

To figure out what @checkin_info returns you could try this:

puts @checkin_info.to_yaml
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜