Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

The "page" parameter on gets #31

Closed
edanm opened this Issue Apr 18, 2012 · 3 comments

Comments

Projects
None yet
2 participants

edanm commented Apr 18, 2012

Hi,

I'm trying to get all the Facebook friends of a certain user. I understand how to do such a request (I just do graph_obj.get("me/friends").

I'm less clear about the issue of paging.

I understand, from the Facebook docs, that Facebook might need to give me more data by giving me a "next" link. First of all, when I make a request for my friends list, Facebook provides me a next link, but it's to a page that has an empty list for data.

As for Facepy, you write in the docs that you can set "Page=True" and then you get back a generator. Does this mean I can now use this generate to run over all the objects, and be sure that Facepy gets any more using the "Next" links if necessary?

I ask because it seems that, if I try to get everything from the generator, it not only gets back the data, but also the metadata like "next" links as well, which I'm not sure why it needs to do.

Thanks for the help!

Owner

jgorset commented Apr 18, 2012

Hi @edanm,

Facepy and Facebook's Graph API are very loosely coupled. In fact, Facepy pretty much only parses and returns the body of the response. This is by design; Facebook's API changes all the time, and a tightly-coupled library would impose upon developers to upgrade it whenever it does.

As for Facepy, you write in the docs that you can set "Page=True" and then you get back a generator. Does this mean I can now use this generate to run over all the objects, and be sure that Facepy gets any more using the "Next" links if necessary?

Yes; the generator iterates by making new requests according to the value of the next attribute of its current iteration.

edanm commented Apr 19, 2012

Thanks for the respone @jgorset. I have a few follow-ups:

OK, so why does the generator also give me the metadata? I would expect the generator to only give me the "data" returned by the request, and use the metadata behind the scenes.

I'm not even clear on the best way to iterate through the generator in this case, since it gives back a dict that contains both the metadata and the data. Do I just access its "data" key through the dict, and trust that it's automatically populated with all the variables, and ignore the metadata part of it?

Sorry for the newb questions, I'm kinda new to this library.

Thanks!

Owner

jgorset commented Apr 21, 2012

No worries, @edanm!

OK, so why does the generator also give me the metadata? I would expect the generator to only give me the "data" returned by the request, and use the metadata behind the scenes.

See #14.

I'm not even clear on the best way to iterate through the generator in this case, since it gives back a dict that contains both the metadata and the data. Do I just access its "data" key through the dict, and trust that it's automatically populated with all the variables, and ignore the metadata part of it?

Yeah.

graph = GraphAPI(access_token)
pages = graph.get("me/feed", page=True)

for page in pages:
    print page["data"]

@jgorset jgorset closed this Apr 24, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment