paginated response Facebook API - facebook

In the Faceboook API, is there a way to get paginated API responses in reverse order? Or take only recent results or something?
Using the "next" link as discussed here (https://developers.facebook.com/docs/graph-api/using-graph-api/v2.1#paging), I can click through, but if there's a ton of results since all the way from 2013, that takes very long.

You can use time based pagination, this is from facebook documentation:
Time-based Pagination
Time pagination is used to navigate through results data using Unix timestamps which point to specific times in a list of data.
When using an endpoint that uses time-based pagination, you will see the following JSON response:
{
"data": [
... Endpoint data is here
],
"paging": {
"previous": "https://graph.facebook.com/me/feed?limit=25&since=1364849754",
"next": "https://graph.facebook.com/me/feed?limit=25&until=1364587774"
}
}
A time-paginated edge supports the following parameters:
until: A Unix timestamp or strtotime data value that points to the end of the range of time-based data.
since: A Unix timestamp or strtotime data value that points to the start of the range of time-based data.
limit: This is the number of individual objects that are returned in each page. A limit of 0 will return no results. Some edges have an upper maximum on the limit value, for performance reasons. We will return the correct pagination links if that happens.
next : The Graph API endpoint that will return the next page of data.
previous : The Graph API endpoint that will return the previous page of data.

Related

Facebook API – Graph Search - get number of event attendees

I use Facebook API Graph Search to explore queries such as:
https://graph.facebook.com/search?q=conference&fields=name,description&type=event
I need to get a list of events by a defined query (without code, SDKs, only url, it’s important for me) with number of attendees for all of events, but this information isn’t as fields, it’s the node of an event. A list of attendees of particular event can be returned with this url:
https://graph.facebook.com/331218348435/attending
Is there any solution to get number of attending. For all events with one url? I mean the same way like fields?
Can I create more specific, complex query within url? FQL is deprecated.
EDIT:
I need this statistics of all events in one call, not for single event.
Use this call: /331218348435?fields=attending.limit(1).summary(true)
With "summary(true)", you will get a "summary" in the result:
"summary": {
"count": 1458
}
If you want to get the attendees count of several Events at once, you can use Batch Requests with up to 50 API calls in one batch: https://developers.facebook.com/docs/graph-api/making-multiple-requests

Facebook Api Graph Pull data from a timeframe

I am new to this stuff, I am trying to use Facebook api Graph to get the data for the last 30 days and link it to Klipfolio.
I am able to pull all the data but no matter what i try I can not seam to get FB to only return all of the data not just last 30 days or 7days.
am I able to a time frame parameters?
Any help would be appreciated, this is what I have to pull all the data,
/adaccounts?fields=amount_spent
Thanks
i don't use facebook adds so i can't exactly test with data . but facebook graph api supports time based pagination of the data . read the time based pagination section at the graph api v2.2 docs page. .
it provides with until and since parameters.
A time-paginated edge supports the following parameters:
until : A Unix timestamp or strtotime data value that points to the
end of the range of time-based data.
since : A Unix timestamp or
strtotime data value that points to the start of the range of
time-based data.
i checked it with end points like
me/feed?until=10/11/2011
and it works as expected . so test the parameter for your required data .

In Facebook API is Next/Prev pagination pointers in the opposite direction?

I'm trying to perform a simple pagination based on time through a facebook endpoint. I was getting results that didn't match my since.
An example call <username>/statuses?since=1390176000
returns this pagination:
"paging": {
"previous": "https://graph.facebook.com/8489236245/statuses?since=1390500000&limit=25&__paging_token=<num>",
"next": "https://graph.facebook.com/8489236245/statuses?limit=25&until=1390250670&__paging_token=<num>"
}
My expected behavior was that after a query with since I will iterate on next till I reach NOW. But when doing the query they provide with until=1390250670 I actually get OLDER results. Is there any logical explanation for this? Should I just use the previous paging ?
As you are looking at the user's statuses, the pagination is reversed as the data is ordered in reverse chronological order. The newest entries are always on the first page, so paginating to the next page will always give you older entries.
Unfortunately, the Facebook documentation doesn't mention the ordering for this API call.

Pagination in the event search API

I am performing a rest call to facebooks search API using type=event
e.x.
search?fields=id,name,picture,owner,description,start_time,end_time,location,venue,updated_time,ticket_uri&q=concert&type=event
I have looked through the documentation and still have a few questions about specific pagination behavior of the event search API.
If I used a broad search term like "ma" and keep querying the pagination ['next'] URL would I cycle through all facebook events starting with "ma"? Does the pagination array give any indication when there are no more results to return?.
Do these searches include past events? If so is it possible to eliminate past events using the "since" parameter?
What is the maximum for the limit parameter?
Update:
As far as I can tell the number of pages you can get from a facebook search is limited to 500. This includes pages that can be accessed via pagination. In other words a query with limit >=500 will not return a pagination url, likewise a query with limit 250 will only return one pages worth of pagination.
You will "next page" until the count of results comes less then the limit
I'm not sure if that is possible using a simple Graph Request. Maybe using FQL
I don't know exactly. But i used a 2000 limit one day. And it worked.
Other doubts you can get answers testing your resquests with this tool
https://developers.facebook.com/tools/explorer/
I am also doing the same thing like you. I am collecting public post using graph search api.
When there are no results available or you reach max limit pagination section will not be there in response. So you can always check for paging is there in json response or not something like this.
NextResult = DeserJsonFBResponce.paging != null ? DeserJsonFBResponce.paging.next : string.Empty;
I am not so sure about this with events but for public post i am able to eliminate post using science and until parameters.
Maximum for the limit parameter is 2000 per get request.

Why are there next AND previous paging URLs in the initial response from a Facebook Graph query?

Why would there be a next AND previous link in the original search results?
Say for example:
https://graph.facebook.com/search?q=car&type=post&access_token=...
At the end of the first page of results you are able to page backwards and forwards? I would have expected to just go forwards then the next result page should have both previous and next.
...]
, "paging": {
"previous": "https://graph.facebook.com/search?q=car&type=post&access_token=...",
"next": "https://graph.facebook.com/search?q=car&type=post&access_token=..."
}
The next and previous on the initial query allows you to at a later time use the links to query the server for newer data then you had previously gotten.
This way you can request ONLY the new data, and have to parse ONLY the new data, and then you can elegantly shove the new data in with the already existing data that you had previously received.
This i presume is why they use a time stamp in the next and previous links as well instead of an offset.
Hope that helps.