Facebook FQL Multi.Query:连接结果集

发布于 2024-12-03 01:02:37 字数 1081 浏览 1 评论 0原文

我正在使用 Facebook 的 fql.multiquery 来处理许多不同的事情,并且我得到了结果 - 正如医生所吩咐的那样。但我似乎不知道如何加入结果,以便我可以按照我想要的方式将它们返回给用户。

我正在使用 HTTParty 来称呼它:

  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

这给了我我想要的东西......但它在 3 个单独的数组/哈希中(?)并且出于某种原因,我的大脑没有得出结论关于如何处理它。

所以基本上,如果我想向用户展示“好吧,伙计,你和这些人在 *LOCATION_NAME*:*FRIENDS_WITH*

我怎样才能获取这 3 个单独的结果集并匹配所有内容?有没有办法包含以前的内容 来回调并匹配它,以便我可以显示所有内容?有些签到没有 tagged_uids,所以显然,当涉及到他们所在的朋友时,仅按顺序执行是行不通的。

查询 JOIN(这看起来可能是一个解决方案) - 但在 FQL 中不可用。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

懷念過去 2024-12-10 01:02:37

我没有使用 FQL 或 HTTParty 的经验,所以我可能完全错误。

我倾向于将sql格式化如下:

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和friends_with可能作为散列数组返回:

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

不确定HTTParty返回什么,但如果它是散列数组的散列,你可以尝试:

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 } }

要弄清楚@checkin_info返回什么,你可以尝试这个:

puts @checkin_info.to_yaml

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文