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?
Just found out that it IS possible! You can use the
IN
operator just with thedevices
column. There is no need to restrict to os or hardware.Example: all friends that have an iPhone: try out
Example: all friends that have an iOS device (e.g. iPhone or iPad): try out
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: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.