How to use devices field of the user table in FQL query?

心不动则不痛 提交于 2019-12-06 16:02:18

问题


I would like the result of a FQL query to only return friends of a user which have a iOS device in their devices list. The following query:

SELECT uid, first_name, devices 
FROM user 
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
ORDER BY profile_update_time DESC 
LIMIT 0, 100

returns a list like this:

{
  "data": [
    {
      "uid": 12345678, 
      "first_name": "John", 
      "devices": [
        {
          "os": "iOS", 
          "hardware": "iPhone"
        }
      ]
    },
    {
      "uid": 1234345678, 
      "first_name": "Pete", 
    }
}

Now I would like to only retrieve users who have at least one device where the os is "iOS". I have tried including

devices.os = "iOS"

in the query but this returned an error.

Is this possible through the FQL query? Or should this be solved client side?


回答1:


Just found out that it IS possible! You can use the IN operator just with the devices column. There is no need to restrict to os or hardware.

Example: all friends that have an iPhone: try out

SELECT uid, name, devices FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
  AND "iPhone" IN devices
ORDER BY profile_update_time DESC 
LIMIT 0, 100

Example: all friends that have an iOS device (e.g. iPhone or iPad): try out

SELECT uid, name, devices FROM user
WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
  AND "iOS" IN devices
ORDER BY profile_update_time DESC 
LIMIT 0, 100

Hint: If you want to use this Query to build a custom Friend Picker to send invites to Facebook friends that not yet have installed your iOS app but have an iOS device, you want to include the following into your WHERE clause:

AND is_app_user = 0



回答2:


This does not appear to be possible on the server side. The devices field is returned as an array, and FQL does not seem to have any methods that can search an array. As far as I can tell, the only way to explore this is on the client side.



来源:https://stackoverflow.com/questions/11684865/how-to-use-devices-field-of-the-user-table-in-fql-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!