1

I'm using one awesome library for using facebook api easier. Here is the link of that library. And here you can see one example, how to get likes of photos from facebook. Now using facebook api you are not fetching all records. You are fetching in most cases 25 records and you need to use pagination for getting next page, and i'm doing that for photos, and i'm getting all user photos, but i'm not getting all likes. This library has two methods hasNext() and getNext() and one returns boolean value for checking if there is one more page and second method is for getting new request.

Here is some part of code:

OnFriendsListener onFriendsListener = new OnFriendsListener() {

    @Override
    public void onComplete(List<Profile> friends) {
        Bundle params = new Bundle();
        params.putCharSequence("fields",
                "source, name, link, images, from, created_time");

        for (Profile profile : friends) {
            activity.getSimpleFacebook().get(profile.getId(), "photos/uploaded", params,
                    new OnActionListener<List<Photo>>() {
                @Override
                public void onComplete(List<Photo> photos) {
                    adapter = new TodayListAdapter(activity, topics);
                    RecyclerView.LayoutManager manager = new LinearLayoutManager(activity);
                    recyclerView.setLayoutManager(manager);
                    recyclerView.setItemAnimator(new DefaultItemAnimator());
                    recyclerView.setAdapter(adapter);

                    for (final Photo photo : photos) {
                        // Initialize instance of Topic
                        final Topic topic = new Topic();
                        final User user = photo.getFrom();

                        activity.getSimpleFacebook().getLikes(photo.getId(),
                                new OnLikesListener() {
                                    @Override
                                    public void onComplete(List<Like> likes) {
                                        topic.setNumOfLikes(likes.size());
                                    }
                                });

                        topic.setPostImage(photo.getSource());
                        topic.setUserId(user.getId());
                        topic.setName(user.getName());
                        topics.add(topic);
                        adapter.notifyDataSetChanged();
                    }

                    if (hasNext()) {
                        getNext();
                    }
                }

                @Override
                public void onThinking() {
                    super.onThinking();
                    hideDialog();
                }
            });
        }
    }
};
Dusan Dimitrijevic
  • 3,169
  • 6
  • 22
  • 46

0 Answers0