Codigami / face4j

face4j is a java library for facebook's new graph API
http://face4j.org
23 stars 6 forks source link

I am using face4j-1.5.11.jar and only able to get name and id and not able to fetch email,birthday and profile photo #27

Open shanks1010 opened 7 years ago

shanks1010 commented 7 years ago

I am trying to fetch user details and oauth authenticate user through facebook api's and java and able to authenticate and redirect to my home page but the facebook api's are not returning details like email , birthday, friend list but only returns username and id and the rest details as null. I have registered my App on facebook and still why i am not able to fetch other details like birthday , email , friendlist,profile picture etc.

Below is the code :

This is Main Menu Class :

 public class MainMenu extends HttpServlet {

    private static final long serialVersionUID = 1L;
    private String code="";

    public void service(HttpServletRequest req, HttpServletResponse res)
            throws ServletException, IOException {      

         String clientId = "XXXXXXXXXXXXXXXXX";
         String clientSecret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
        //public static final String REDIRECT_URI = "http://localhost:8080/Facebook_Login/fbhome";

        Client client = new Client(clientId, clientSecret);
        FacebookFactory facebookFactory = new FacebookFactory(client);
        String redirectURL = facebookFactory.getRedirectURL("http://localhost:8080/Facebook_Login/fbhome", Display.POPUP, Permission.EMAIL, Permission.OFFLINE_ACCESS);
        String code = req.getParameter("code");
        OAuthAccessToken accessToken1;
        try {
            accessToken1 = facebookFactory.getOAuthAccessToken(code, "http://localhost:8080/Facebook_Login/fbhome");

        Facebook facebook = facebookFactory.getInstance(accessToken1);
        User fbUser = facebook.getCurrentUser();

        System.out.println("fbUser"+"====="+fbUser.getName());

        ServletOutputStream out = res.getOutputStream();
        res.reset();
        out.println("<h1>Facebook Login using Java</h1>");
        out.println("<h2>Application Main Menu</h2>");
        out.println("<div>Welcome "+fbUser.getName());
        out.println("<div>Your Religion: "+fbUser.getReligion());
        out.println("<div>Your Birthday: "+fbUser.getBirthday());

        out.println("<div>Your Gender: "+fbUser.getGender());
        out.println("<div>Your Locale: "+fbUser.getLocale());

        out.println("<div>Your ID: "+fbUser.getWork());
        out.println("<div>Logout: "+"<a href='https://www.facebook.com/logout.php?next="+"http://localhost:8080/Facebook_Login/fbhome&access_token="+accessToken1+"'>Logout"+"</>");

        //out.println("<div>Your Education: "+fbUser.home(facebook));
        Map<String, String> fbProfile = new HashMap<String, String>();
        JSONObject json = new JSONObject(fbUser);
        try {
            fbProfile.put("id", json.getString("id"));
            System.out.println("fbProfile"+fbProfile);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        } catch (FacebookException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

        }

        /*out.println("<div>You are "+fbProfileData.get("gender"));
        out.flush();*/

    }

}

and I am using face4j-1.5.11.jar

Below is the html

!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Java Facebook Login</title>
</head>
<body style="text-align: center; margin: 0 auto;">
    <div
        >
        <a href="<%=fbConnection.getFBAuthUrl()%>"> <img
            style="margin-top: 138px;" src="./img/facebookloginbutton.png" />
        </a>
    </div>
</body>
</html>