Getting user Id from session after Facebook login

-2

I'm working with Codenameone, and integrated Facebook login and worked so well, the good thing is that when I reload my emulator the session is always on, What I actually want to do is to get the user Information and save it in my database in the user's table. Is there a tutorial or something that could help me. Thank you.

 private void showIfLoggedIn(UserForm form) {
        String token = (String) Storage.getInstance().readObject("token");
        FaceBookAccess.setToken(token);
            final User me = new User();
            try {
                FaceBookAccess.getInstance().getUser("me", me, new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent evt) {
                        String miNombre = me.getName();
                          String email = me.getEmail();
                        form.getContentPane().removeAll();                            
                        form.add(new Label(miNombre));                          
                        Button buttonLogout = new Button("Logout");
                        buttonLogout.addActionListener((e) -> {
                            facebookLogout(form);
                            showIfNotLoggedIn(form);
                        });
                        EncodedImage placeholder = EncodedImage.createFromImage(Image.createImage(50, 50, 0xffff0000), true);
                        URLImage background = URLImage.createToStorage(placeholder, "fbuser.jpg",
                        "https://graph.facebook.com/v2.11/me/picture?access_token=" + token);
                        background.fetch();
                        ScaleImageLabel myPic = new ScaleImageLabel();
                        myPic.setIcon(background);                       
                        form.add(myPic);
                        form.add(email);
                        form.add(buttonLogout);                       
                        form.revalidate();
                    }                       
                });
            } catch (IOException ex) {
                ex.printStackTrace();
                showIfNotLoggedIn(form);
            }
    }
java
facebook
codenameone
asked on Stack Overflow Apr 28, 2019 by Firas Jerbi • edited Apr 28, 2019 by Firas Jerbi

1 Answer

0

The code in FacebookAccess is deprecated as that's pretty old. It predated the native FacebookConnect API. There's this sample here: https://www.codenameone.com/blog/building-a-chat-app-with-codename-one-part-3.html

It includes code to access facebook using the graph API and the token data. This uses the old graph API version so you might need to update the syntax a bit but the gist remains the same.

answered on Stack Overflow Apr 29, 2019 by Shai Almog

User contributions licensed under CC BY-SA 3.0