Facebook Graph API: Receive Total Messages

I use the Facebook API to display user posts. When I get the start page of the posts, the resulting data object has a paging property object with the previous and next URL attribute. I was hoping to create navigation links based on this available paging information. However, sometimes these URLs point to an empty dataset, so I obviously don't want to move the user to a blank page.

Is there a way to find the total number of objects in the collection so that I can get a better navigation? Is there a way to get more intelligent swap data?

Update: Sorry if my post is not clear. To illustrate this, review the data at https://graph.facebook.com/7901103/posts and its URLs for paging properties. Then follow these URLs to see the problem: blank data pages.

+4
source share
3 answers

Since it prints data with a date and time base. You cannot find out if there is data or not before submitting a request for it. But you can preload the data from the previous URL to determine if the previous link on your web page is suitable for sending.

+1
source

Why be addicted to Facebook?
Why don't you preload all the data for the user and save it in the database. Then you get messages from db and show to the user. Thus, you all control how many messages there are and how to manage the next and previous.

+1
source

I was going to try to post this as a comment on your question, but I can't do it ...

I know that the Graph API returns JSON, and although I have never encountered getting the total number of messages returned, depending on what technology you use to process the response, you can size the JSON array containing the messages.

For example, if I used a java application, I could use the libraries available on json.org (or Google GSON or XStream with the JSON driver) to populate the object, and then just use the JSONArray.length () method to check the number of messages returned.

see: http://www.json.org/javadoc/org/json/JSONArray.html

This may seem like a slightly simplified solution, but it may be the type of work around you if you cannot find a way to return this data to Facebook.

Can you indicate what technology your application is based on?

0
source

Source: https://habr.com/ru/post/1332052/


All Articles