Here is the code. In the result I want to see my conversation and my friend conversation. For conversation history functionality How can I do this?
SELECT message_id, thread_id, author_id, body, created_time, viewer_id
FROM message WHERE thread_id IN
(SELECT thread_id, subject, recipients FROM thread WHERE folder_id =0 )
AND author_id = 'xxxxxxxxxxxxxxx' ORDER BY created_time DESC LIMIT 0,25
This code returns only my friend data.
You've restricted the comments returned to those authored by your friend only.
Change
AND author_id = FRIEND_ID
to
AND (author_id = FRIEND_ID OR author_id = me())
in the `WHERE clause of your query.
Get a thread_id by using your original query and then try this fql query. I think a thread_id belongs to whole conversation
SELECT message_id, thread_id,source,author_id,body,created_time,viewer_id FROM
message WHERE thread_id=THREAD_id AND (author_id=FRIEND_ID OR
author_id=me() ) ORDER BY created_time DESC LIMIT 0,25
Related
New to FQL and wanted to extract "OTHER" mailbox archived or not and group all body messages by user. The query example below grabs each message and in INBOX only. folder_id is 0 for inbox, 1 for outbox and 4 for updates. What is the option for the OTHER inbox?
SELECT message_id, thread_id, author_id, body, created_time, attachment FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0)
Use OR operator
SELECT message_id, thread_id, author_id, body, created_time, attachment FROM message WHERE thread_id IN (SELECT thread_id FROM thread WHERE folder_id = 0 OR folder_id = 1 OR folder_id = 4)
I am trying to create an OR clause in FQL query.
Here is my query :
SELECT post_id, message, permalink, likes, actor_id, created_time FROM stream WHERE
(source_id = xxx1 AND message != '' AND actor_id = xxx2)
OR
(source_id = xxx2 AND actor_id = xxx1)
Globally I want to retrieve all the messages between 2 Facebook users.
If I remove the OR clause I do receive messages in one way but adding the OR removes every messages I have as if the '(' do not work.
If you need to test this query please go on : http://developers.facebook.com/tools/explorer
and create and access token with the read_stream permission (Extended Permissions)
I also wanted to use a UNION but it is not supported by FQL.
Maybe I could use FQL multiple queries but I was still blocked by the UNION missing.
Thank you for your help.
You can use sub queries to achieve the desired result like this:
SELECT post_id, message FROM stream
WHERE
(
post_id in (select post_id from stream where actor_id = uid0 and source_id = uid1)
or
post_id in (select post_id from stream where actor_id = uid1 and source_id = uid0)
)
and message != ''
The answer provided by complex857 is correct but I would like to add some information.
To make this query work you must add a LIMIT / OFFSET clause to your query.
SELECT post_id FROM stream
WHERE
(post_id IN (SELECT post_id FROM stream WHERE source_id = uid0 AND actor_id = uid1 LIMIT 1000 OFFSET 0)
OR
post_id IN (SELECT post_id FROM stream WHERE source_id = uid1 AND actor_id = uid0 LIMIT 1000 OFFSET 0))
AND message != '';
Hope this will help :)
Is there a way to get all of the photos form a given stream query? I tried the following but it returns an empty set.
SELECT pid, aid, src_big FROM photo WHERE pid IN (SELECT attachment.media.photo.pid FROM #feed)
Its tough to tell since I can't see your '#feed' query but more than likely you are missing a stream_filter query. This would give you something like the following 3 queries. Good Luck!
Query 'key':
SELECT filter_key
FROM stream_filter
WHERE uid = me() AND name = 'Photos'
Query 'feed':
SELECT attachment.media.photo.pid
FROM stream
WHERE source_id = {id here} AND filter_key IN (SELECT filter FROM #key)
Query 'photos':
SELECT caption, src_big, modified
FROM photo
WHERE pid IN (SELECT pid FROM #feed)
SELECT pid FROM photo WHERE me() and $otherPerson IN ( SELECT subject FROM photo_tag WHERE pid=pid ) ORDER BY created DESC LIMIT 1
I'm trying to get a photo that has both users tagged in it ($otherPerson is replaced with a user id). This query returns:
604 Your statement is not indexable. The WHERE clause must contain an indexable column. Such columns are marked with * in the tables linked from http://wiki.developers.facebook.com/index.php/FQL_Tables
Any ideas on how I can make this work?
UPDATE:
I currently have this query working but I feel as though there's a better way to go about.
SELECT pid, src_big FROM photo
WHERE pid IN (
SELECT pid FROM photo_tag
WHERE subject=$otherGuy
AND pid in (
SELECT pid FROM photo_tag WHERE subject=me()
)
)
This should do the trick.
SELECT pid, src_big
FROM photo
WHERE pid IN(
SELECT pid
FROM photo_tag
WHERE subject = me()
)
AND pid IN(
SELECT pid
FROM photo_tag
WHERE subject = <friend_user_id>
)
What about:
SELECT pid
FROM photo
WHERE me() IN (SELECT subject
FROM photo_tag
WHERE pid=pid)
AND $otherPerson IN (SELECT subject
FROM photo_tag
WHERE pid=pid)
ORDER BY created DESC
LIMIT 1
Also, what pid=pid means?
I tried the other solutions and ran into a problem - If your friend has set his privacy settings to disallow apps from accessing his photos, then the following FQL query will return an empty table:
"SELECT pid FROM photo_tag WHERE subject = <friend_user_id>"
I solved this by using the following multiquery instead:
"query1" : "SELECT subject, pid FROM photo_tag WHERE pid IN (SELECT pid FROM photo_tag WHERE subject=me())"
"query2" : "SELECT pid FROM #query1 WHERE subject= <friend_user_id>"
I'm using FQL to get data from user's stream to build a web page looks like wall-to-wall. With two queries:
query = "SELECT post_id, message, created_time FROM stream WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid="+user['uid']+" AND type='newsfeed') AND target_id = "+uid+" AND actor_id = "+user['uid']+" LIMIT 5"
and
query = "SELECT post_id, message, created_time FROM stream WHERE filter_key IN (SELECT filter_key FROM stream_filter WHERE uid="+user['uid']+" AND type='newsfeed') AND target_id = "+user['uid']+" AND actor_id = "+uid+" LIMIT 5"
they only return:
{}
What's wrong in my queries ?
Thank you :)
try checking the values you are using for uid..
target_id means the wall it was posted to, ONLY if the wall was not the actor_id's wall..
Both will never be equal.