Home » Android » How to retrieve all tagged facebook photos from the facebook sdk

How to retrieve all tagged facebook photos from the facebook sdk

Posted by: admin November 1, 2017 Leave a comment

Questions:

After many attempts I have been unable to retrieve all of my tagged photos from the facebook sdk. I would like something similar to what tinder has, but my query only returns 110 photos, of which some repeat, compared to tinder retrieving all 296 tagged photos.

Here is the code for my request:

Bundle paramaters = new Bundle();

    paramaters.putString("fields", "source");
    paramaters.putInt("limit", 1000);

    new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/" + userId + "/photos",
            paramaters,
            HttpMethod.GET,
            graphCallback

    ).executeAsync();

GraphRequest.Callback graphCallback = new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {

        try {

            if (response.getError() == null) {

                JSONObject joMain = response.getJSONObject();
                if (joMain.has("data")) {
                    final JSONArray jaData = joMain.optJSONArray("data");

                    for (int i = 0; i < jaData.length(); i++) {

                        JSONObject joImages = jaData.getJSONObject(i);
                        String url = (String) joImages.get("source");

                        if (i == 0) {
                            facebookAlbum.setDisplayUrl(url);
                        }
                        facebookAlbum.addImage(url);
                        albumnListAdapter.notifyDataSetChanged();

                    }
                }
            }

            GraphRequest nextRequest = response.getRequestForPagedResults(GraphResponse.PagingDirection.NEXT);
            if(nextRequest != null) {
                nextRequest.setCallback(this);
                nextRequest.executeAsync();
            }

        }

        catch (Exception e) {
            e.printStackTrace();
        }
    }
};
Answers: