Reputation: 55
I'd like to search pages using Graph API and sort search results according to the number of likes. But apparently there's no way to add any parameter to sort search results rather than iterating through each page for its number of likes.
Also I didn't find any information about how Graph API's search function decides order of the results. If I search for a page with same search term (for example, Volkswagen) using different access token, the order of the search results are different. So apparently there's a deciding factor for ordering search results. Does anybody know how Graph API sorts search results by default?
Upvotes: 4
Views: 8174
Reputation: 11
facebook provides the chronological
and reverse_chronological
, similar to
ascending and descending order respectively, and can be used like this;
https://graph.facebook.com/1809938745705498fields=comments.order(chronological).limit(3)
You can also take a look at the documentation here
Upvotes: 0
Reputation: 96250
The API doesn’t offer sorting for most endpoints.
You can get the fan count for the returned pages within the same request though, by using field expansion:
/search?type=page&q=blah&fields=id,name,fan_count
– then you can use that to do the sorting on your end. Spares you from having to make extra requests - but depending on how many pages your search returns (pages as in pagination here, not FB pages), you might need to fetch all of them before you do the sorting.
Also I didn't find any information about how Graph API's search function decides order of the results. If I search for a page with same search term (for example, Volkswagen) using different access token, the order of the search results are different.
When you use a user access token, then the search results are tailored to the specific user the token belongs to.
You can also use your app access token to perform this search - but then you will only get public pages that are not access-restricted in any way. If you use a user access token, then it will take into account which non-public pages that specific user can see.
Upvotes: 6