Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I convert the following code to get a list of the members in a group thro

ID: 3605872 • Letter: H

Question

How do I convert the following code to get a list of the members in a group through a group id? I'm currently using facebook api developer, restfb library, and netbean.


import com.restfb.Connection;
import com.restfb.DefaultFacebookClient;
import com.restfb.FacebookClient;
import com.restfb.types.Group;
import com.restfb.types.User;
import java.util.List;
import java.util.Scanner;

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author
*/
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
      
        String accessToken = "insert your accessToken here";
          
        Scanner input = new Scanner(System.in);
      
        FacebookClient fbClient = new DefaultFacebookClient(accessToken);
      
        Connection<Group> groupsFeed = fbClient.fetchConnection("me/groups", Group.class);
      
        for(List<Group> page : groupsFeed){
            for(Group aGroup : page){
                System.out.println("Do you want to get Memebers of "+aGroup.getName()+" ? Yes/NO");
                String ans = input.nextLine();
                if(ans.equals("Yes")){
                  
                    System.out.println("fb.com/"+aGroup.getId());
                  
                    Connection<User> userFeed = fbClient.fetchConnection(aGroup.getId()+"/members", User.class);
                  
                    for(List<User> userPage: userFeed){
                        for(User aUser : userPage){
                          
                            System.out.println(aUser.getName());
                            System.out.println("fb.com/"+aUser.getId());
                          
                        }

                    }
                }
            }
        }
      
    }
  
}

Explanation / Answer

Hi,

I have modified your code a little. Your code was good enough to get members of a group, I have made very few changes and added a Map to store groupId with a List of members. Please find the code below:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote