I am trying to get the body and the sender of all unread inbox .
To get all conversation's threads with unread messages I used this query:
SELECT thread_id from unified_thread WHERE folder='inbox' AND unread=1
to get the unread message of a thread I used this query
SELECT sender,body FROM unified_message WHERE unread=1
I have tried the following nested query :
SELECT sender,body FROM unified_message WHERE thread_id IN (SELECT thread_id FROM unified_thread WHERE folder = 'inbox' AND unread=1) AND unread=1"
but I only get unread message from one thread and not all unread threads.
I also tried multiquery like this:
String query1="SELECT thread_id FROM unified_thread WHERE folder='inbox' AND unread=1";
String query2="SELECT timestamp,sender,body FROM unified_message WHERE unread=1 AND thread_id IN (SELECT thread_id FROM #query1)";
Bundle params = new Bundle();
JSONObject jsonFQL=new JSONObject();
try {
jsonFQL.put("query1",query1);
jsonFQL.put("query2",query2);
} catch (JSONException e) {
e.printStackTrace();
}
params.putString("method","fql.multiquery");
params.putString("queries", jsonFQL.toString());
new Request(session,"/fql",params,HttpMethod.GET,new Request.Callback(){
public void onCompleted(Response response) {
...
}
).executeAsync(); ....
but I got error:
errorMessage: Unsupported method, fql.multiquery
Then I tried with INNER JOIN:
SELECT unified_message.sender,unified_message.body
FROM unified_message
INNER JOIN unified_thread
ON unified_message.thread_id=unified_thread.thread_id
WHERE unified_thread.unread=1
but I got this error:
Parser error: unexpected 'INNER' at position...
I learnt JOIN is not supported in FQL
Can somebody give me a hand to do this query in FQL ??
example of needed output: I have 5 conversations with different people, but only 3 conversations have unread messages. So I would like to get something like this:
UNREAD MESSAGES
Sender: Anna
Body: hello dude
Body: how are you?
Body: I miss you
Sender: John
Body: please help me
Sender: Erick
Body: nice
Body: buddy
This works:
It is important to sort the messages you retrieve in a descending order using:
Otherwise, only the first older messages of the conversation will be examined, whereas unread messages should be recent.
Just for your knowledge, here is the corresponding multi-query, which gives the same result:
However, you should not use FQL anymore:
I suggest you use the following Graph API tables:
thread
message
By the way, FQL doesn't have such
INNER JOIN
.Multi-query:
Evaluates a series of FQL (Facebook Query Language) queries in one call and returns the data at one time.
This method takes a JSON-encoded dictionary called ''queries'' where the individual queries use the exact same syntax as a simple query. However, this method allows for more complex queries to be made. You can fetch data from one query and use it in another query within the same call. The WHERE clause is optional in the latter query, since it references data that’s already been fetched. To reference the results of one query in another query within the same call, specify its name in the FROM clause, preceded by #.
For example, say you want to get some data about a user attending an event. Normally, you’d have to perform two queries in a row, waiting for the results of the first query before running the second query, since the second query depends on data from the first one. But with fql.multiquery, you can run them at the same time, and get all the results you need, giving you better performance than running a series of fql.query calls. First, you need to get the user ID and RSVP status of each attendee, so you’d formulate the first query – query1 – like this:
*
*
Then to get each attendee’s profile data (name, URL, and picture in this instance), you’d make a second query – query2 – which references the results from query1. You formulate query2 like this:
"*
*"
https://developers.facebook.com/docs/technical-guides/fql
This nested query you placed
SELECT sender,body FROM unified_message WHERE thread_id IN (SELECT thread_id FROM unified_thread WHERE folder = 'inbox' AND unread=1) AND unread=1
should work. If it doesn't, consider filing a bug.
Breaking it down,
SELECT thread_id FROM unified_thread WHERE folder = 'inbox' AND unread=1
Should give you the thread ids for threads with unread messages. The only catch here is that
unified_thread
doesn't necessarily return all threads even withLIMIT
applied. So what you did here was good (as long as the unread response set is small enough)If at this point, the numbers aren't matching what you have, it doesn't make sense to move further in the query. File a bug.
The larger query
SELECT sender,body FROM unified_message WHERE thread_id IN (SELECT thread_id FROM unified_thread WHERE folder = 'inbox' AND unread=1) AND unread=1
Checks all messages within the thread, so as long as your thread ids are valid and correctly counted then there is nothing to worry about here.
Ensure you are getting the correct count of unread threads first If not, as I said before, file a bug.
So that with this query
SELECT thread_id, participants, link FROM unified_thread WHERE folder = 'inbox' AND unread
Cross check that the participants and links match what you have in your inbox.
I am not entirely sure if this fixes your problem, but it seems that the parameter is "q", not "queries":
...if you take a look at the Facebook docs:
https://developers.facebook.com/docs/technical-guides/fql
Could be possible that they changed it recently, although it is deprecated so i dont think they will put much effort into it.