我正在尝试获取所有未读收件箱的正文和发件人。
要使用未读消息获取所有对话线程,我使用了以下查询:SELECT thread_id from unified_thread WHERE folder='inbox' AND unread=1
获取线程的未读消息我使用了这个查询SELECT sender,body FROM unified_message WHERE unread=1
我尝试了以下嵌套查询:
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"
但我只从一个线程收到未读消息,而不是所有未读线程。
我也试过这样的多查询:
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(); ....
但我有错误:
然后我尝试使用 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
但我收到了这个错误:
我了解到 FQL 不支持 JOIN
有人可以帮我用 FQL 做这个查询吗??
所需输出示例:我与不同的人进行了 5 次对话,但只有 3 次对话有未读消息。所以我想得到
像这样:
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
最佳答案
这有效:
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
ORDER BY timestamp DESC
使用以下方法按降序对检索到的消息进行排序很重要:
ORDER BY timestamp DESC
否则,只会检查对话的第一个 较旧的 消息,而未读消息应该是最近的。
仅供引用,这里是相应的多查询,它给出了相同的结果:
{
"threads":"SELECT thread_id FROM unified_thread WHERE folder='inbox' AND unread=1",
"messages":"SELECT sender, body FROM unified_message WHERE thread_id IN (SELECT thread_id FROM #threads) AND unread=1 ORDER BY timestamp DESC"
}
但是,您不应再使用 FQL:
我建议您使用以下图形 API 表:
thread
message
顺便说一句,FQL 没有这样的
INNER JOIN
。关于android - 如何使用 FQL 获取未读消息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25016843/