Android Facebook album photos request only returns

2019-09-19 01:03发布

问题:

So i am trying to display facebook photos from an album in and Android app.

The problem i am having is if i call this:

facebookAsyncRunner.request(albumId + "/photos", new UserAlbumPhotosFetchListener(JSONResponse, photoView));

i get a JSONResponse of an array of 25 photos. However, i need more than just 25 photos... i need all of them in the album. So i tried calling this:

facebookAsyncRunner.request(albumId + "/photos?limit=50", new UserAlbumPhotosFetchListener(JSONResponse, photoView));

in an attempt to get 50 photos instead of 25. This did not work. Instead i got nothing. I also tried calling this same thing with limit=0, but this is giving me the same result. to be specific: JSONResponse.getJSONArray("data") = []

Does anyone have any idea of what is happening/ how to request more than just 25 photos from an album?

thanks!

EDIT: I found a solution!

Bundle params = new Bundle(); params.putString("limit", "10"); facebookAsyncRunner.request(albumId + "/photos", params, new UserAlbumPhotosFetchListener(JSONResponse, photoView));

回答1:

I have posted an answer which integrates pagination for an Endless Scrolling List here:

https://stackoverflow.com/a/13265776/450534

It is too big to post all over again, so am linking to the original answer instead. The answer is literally a complete a solution on how to make a Facebook query to an Album, fetch all photos (limited initially with a limit=10) and then fetching additional photos from the album when the user has scrolled down to the end and adding them to the existing list of Photos already fetched.

It uses a GridView instead of a ListView but the logic remain the exact same.

Alternatively, if you are looking only for a way to fetch Photos, here is a far simpler solution to get you started.

try {
    String test = Utility.mFacebook.request("/10151498156121729/photos&access_token=YOUR_ACCESS_TOKEN?limit=1");
    Log.e("TEST", test);
} catch (Exception e) {
    // TODO: handle exception
}

The Album ID (10151498156121729) used in the code block above, is a Facebook Public Album.

I use the Utility class from the pre-3.0 Facebook SDK's HackBook example. If you are using the 3.0 SDK, I think you will need to substitute the Utility.mFacebook.request bit with an instance of the Facebook class



回答2:

You should need to use Pagination for getting more than 25 photos. You can get only 25 items as result for a single query. To load the next 25 you should use the code like below:

facebookAsyncRunner.request(albumId + "/photos?offset=25&limit=25", new UserAlbumPhotosFetchListener(JSONResponse, photoView));

this will return the next 25 items, in this case the photos from 25th position to 50th position.

Try in this way.. Hope this may solve your problem.