Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 this issue Jan 22, 2017 · 0 comments

Comments

@shanks1010
Copy link

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant