Dany19
Dany19

Reputation: 551

How to get unread messages using Graph API?

I am developing an app that gets Facebook unread inbox message .

The following v2.0 FQL query works fine:

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

As a result, we have a list of all unread messages.


But, 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.

So, I am looking for a way to do that with Graph API only. I tried the following:

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();

without success. I get all the threads whereas I only need the unread threads. How to do that then?

Upvotes: 1

Views: 3946

Answers (1)

Stéphane Bruckert
Stéphane Bruckert

Reputation: 22903

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...

Upvotes: 3

Related Questions