简体   繁体   English

在 Facebook 登录后从会话中获取用户 ID

[英]Getting user Id from session after Facebook login

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.我正在使用 Codenameone,并且集成了 Facebook 登录并且运行良好,好处是当我重新加载我的模拟器时,会话始终处于开启状态,我真正想做的是获取用户信息并将其保存在我的数据库中在用户表中。 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);
            }
    }

The code in FacebookAccess is deprecated as that's pretty old. FacebookAccess的代码已被弃用,因为它已经很旧了。 It predated the native FacebookConnect API.它早于本机FacebookConnect API。 There's this sample here: https://www.codenameone.com/blog/building-a-chat-app-with-codename-one-part-3.html这里有这个示例: 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.它包括使用图形 API 和令牌数据访问 facebook 的代码。 This uses the old graph API version so you might need to update the syntax a bit but the gist remains the same.这使用旧的图形 API 版本,因此您可能需要稍微更新语法,但要点保持不变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM