1

我正在开发一个获取 Facebook 未读收件箱消息的应用程序。

以下 v2.0 FQL 查询工作正常:

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

结果,我们得到了所有未读消息的列表。


但是,Facebook 说

Facebook 平台 API 2.0 版是 FQL 可用的最后一个版本。2.0 之后的版本将不支持 FQL。请迁移您的应用程序以使用 Graph API 而不是 FQL。请查看我们的变更日志以获取当前版本信息。

所以,我正在寻找一种仅使用 Graph API 的方法。我尝试了以下方法:

Bundle params = new Bundle();
    params.putString("unread", ">0");
    new Request(session,"/me/inbox/",params,HttpMethod.GET,new Request.Callback() {
        public void onCompleted(Response response) {
            ...
        }
    }  
).executeAsync();

没有成功。我得到所有线程,而我只需要未读线程。那该怎么做呢?

4

1 回答 1

3

I am sorry for the advice I gave when I blindly quoted the following Facebook notice:

However, you should not use FQL anymore:

Version 2.0 of the Facebook Platform API is the last version where FQL will be available. Versions after 2.0 will not support FQL. Please migrate your applications to use Graph API instead of FQL. Please see our changelog for current version information.

This statement is true, but to follow it isn't very smart.


Indeed, I checked further and found out:

I didn't expect the Graph API to be so weak. The Graph API makes it impossible to build a request by filtering any field. For example, we can't do simple things such as:

  • me/threads?unread_count>0,
  • me/threads?fields=unread_count.more(0).

Right now with Graph, you would have to iterate through all the threads and check which one have unread > 0. You would lose time and bandwidth. Moreover, the message table doesn't even have an unread field which would make it impossible for you to find any specific unread message(s).

So, the best is to keep using FQL. You are safe for now. By 2016, Facebook will probably have improved the way we query with Graph API.

Wait and see...

于 2014-08-13T19:40:39.277 回答