Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

The "page" parameter on gets #31

Closed
edanm opened this Issue · 3 comments

2 participants

@edanm

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!

@jgorset
Owner

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

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!

@jgorset
Owner

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.