有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何使用Graph API获取未读消息?

我正在开发一个应用程序,可以获取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 says

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.

所以,我正在寻找一种只使用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();

没有成功。我得到所有的线程,而我只需要未读的线程。那怎么办


共 (1) 个答案

  1. # 1 楼答案

    当我盲目引用以下Facebook通知时,我很抱歉给出了建议:

    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.

    这句话是真的,但遵循它并不明智


    事实上,我进一步检查后发现:

    我没想到Graph API这么弱。Graph API不可能通过过滤任何字段来构建请求。例如,我们不能做简单的事情,比如:

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

    现在使用Graph,您必须迭代所有线程,并检查哪个线程有unread > 0。你会损失时间和带宽。此外,message表甚至没有unread字段,这将使您无法找到任何特定的未读消息

    所以,最好是继续使用FQL。你现在很安全。到2016年,Facebook可能会改进我们使用Graph API进行查询的方式

    等着瞧