How to use devices field of the user table in FQL

2020-07-27 15:52发布

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?

2条回答
贪生不怕死
2楼-- · 2020-07-27 16:19

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
查看更多
Summer. ? 凉城
3楼-- · 2020-07-27 16:21

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.

查看更多
登录 后发表回答