I am using Tornado to get the friends of a user from FB’s API. The response contains a single page of the results and I want to move to the next page. How do you do that? Do you use facebook_request() again with the relative path parsed from the next page url?
Share
I haven’t used tornado and the facebook API together before, but Facebook’s response should be formatted like a JSON object, with a ‘paging’ attribute that has ‘next’ and/or ‘previous’ attributes containing urls of other pages (if they exist). So you should be able to just do an http request to get the next page, which will be a JSON response also.
In your callback function, you should probably be able to parse the friend list and add the friends to your list, then check if there’s a next link; if so, send an async http request to that url, with the callback being the same callback as the original request, otherwise you’ve got all the friends and can do whatever you want with them.
Edit:
OK, I haven’t tried this so it might have bugs, but I think it’d be something like:
Where I commented to do the next request, you should probably first parse the next_url to get all of its parameters (basically split by ‘&’ and then split those by ‘=’ to get names and values of parameters) then pass those to another facebook_request as above. Does that make sense?