fql OR and order by desc with offset - facebook

I have some issue with a Facebook's fql request :).
When I request like this
SELECT uid, profile_url
FROM user where contains('potatoe') OR uid in(select id from profile where contains ('potatoe'))
ORDER BY mutual_friend_count desc LIMIT 0,2
I have always the same results, even if I change the offset...
But
If I change DESC to ASC the "offset" works...
If I change OR to AND
and let the order by desc => the "offset" works too!
Something is wrong with my OR/desc/offset combo?
Or I just have misunderstood something with "or" operators? :/
Thanks a lot.

You should write your FQL query like that:
SELECT uid, profile_url
FROM user
where
uid in(select uid from user where contains ('potatoe') )
OR uid in(
select id from profile where contains ('potatoe')
)
ORDER BY mutual_friend_count desc
LIMIT 0,2
FQL couldn't interpret in boolean expression the result of "contains", so your OR operator failed here...

I think the problem is your query is asking the same question two different ways:
Show me all my friends user profiles that contain 'potatoe' OR
Show me all profiles that belong to users who are my friends that contain 'potatoe'.
Simplify your query to this and see if it works as expected.
SELECT uid, profile_url FROM user WHERE contains('potatoe')
ORDER BY mutual_friend_count DESC LIMIT 0,2

Related

Facebook FQL Query Order By Using Multiple Columns

I have a Facebook FQL query which in which everything is going good but what I want is to Order the results by 2 columns.
Here is the last line of the script and until this it is working.
IN (SELECT aid FROM album WHERE owner=133025843429181)ORDER BY created desc
What I want is to order it by created desc and like_info desc, so this is what I am trying and it returns an error.
IN (SELECT aid FROM album WHERE owner=133025843429181)ORDER BY created desc, like_info desc
This is not working. I tried to remove the comma in between and still not working
IN (SELECT aid FROM album WHERE owner=133025843429181)ORDER BY created desc like_info desc
Any solution for this?
Please try the below code: It might be the fix you need
IN (SELECT aid FROM album WHERE owner=133025843429181) ORDER BY (created desc * like_info desc) DESC
This isn't possible.
FQL can handle simple math, basic boolean operators, AND or NOT logical operators, and ORDER BY and LIMIT clauses. ORDER BY can contain only a single table.
https://developers.facebook.com/docs/technical-guides/fql#query

Facebook FQL getting all my friends last position update

I'm trying to get all my friend's last position update with this fql query:
SELECT author_uid, message, latitude, longitude, timestamp FROM location_post WHERE author_uid IN (SELECT uid2 FROM friend WHERE uid1 = me())
I would like to take just the latest update for every friend but this query returns me more than one update for a single friend.
I tried to set a limit at the end of the query (equal to the number of my friends) but it does not work.
How I should change it?
If it was a normal database, not a facebook FQL, you could use join and get your results in single query. Unfortunately Facebook FQL does not allow joins or even max function.
But you can:
Receive all the friend ids like in your query
SELECT uid2 FROM friend WHERE uid1 = me()
Then for each friend uid run the query
SELECT author_uid, message, latitude, longitude, timestamp FROM location_post
WHERE author_uid = FRIEND_ID order by timestamp desc limit 1

Get list of people who liked a status through FQL

I can get the number of likes on a status through this FQL query -
SELECT like_info,
message,
status_id,
time,
uid
FROM status
WHERE uid = me()
I'd like to get the separate user ID's of the likes (if not possible for friends of the authenticated user, just the user himself/herself). It's possible through the Graph API through a command like this -
me/?fields=statuses
Is the same thing possible through FQL?
You can select IDs from status table for user and then use them to select data from like table
SELECT user_id,
object_id
FROM like
WHERE object_id IN(
SELECT status_id
FROM status
WHERE uid = me() )
You may group result by object_id on your side.

FQL Multiquery Returned Info

I'm trying to use an FQL Multiquery to obtain my most recent Facebook question and options with one query using an http request.
So far the query I tried to use is:
SELECT name, votes FROM question_option WHERE question_id IN
(SELECT id, question FROM question WHERE owner = me()
ORDER BY created_time DESC LIMIT 1)
Unfortunately this only returns the name and votes from the outer query and not the question text from the inner one. Is there a way to retrieve all 3 without making 2 queries?
What you posted isn't a multiquery. A proper multiquery should get you what you want:
{
'question_detail':
'SELECT id, question FROM question WHERE owner = me()
ORDER BY created_time DESC LIMIT 1',
'question_answers':
'SELECT name, votes FROM question_option WHERE question_id IN
(SELECT id FROM #question_detail)'
}
You'll need to get rid of the whitespace for this to properly execute.

Facebook's fql improper ORDER BY sorting

I have this fql query:
SELECT link_id, owner, owner_comment, created_time, title, summary, url, image_urls
FROM link
WHERE owner IN (SELECT uid2
FROM friend
WHERE uid1 = me())
ORDER BY created_time DESC
LIMIT 0,200;
It's supposed to display last 200 posted links by my friends, but it displays them ordered by owner id ASC then by created_time DESC.
Is ORDER BY in fql limited to one use? How can I make it work?
I suspect the problem is the LIMIT statement. FQL has some odd internal behaviors to optimize their own internal API.
Try removing the LIMIT statement and just give it a specific AND created_time > <point in time> and see if it orders properly. If so, that's why.