java - Facebook登录后从会话中获取用户ID
问题描述
我正在使用 Codenameone,并集成了 Facebook 登录并且运行良好,好消息是当我重新加载我的模拟器时,会话始终处于开启状态,我真正想要做的是获取用户信息并将其保存在我的数据库中在用户表中。有没有教程或可以帮助我的东西。谢谢你。
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);
}
}
解决方案
不推荐使用中的代码,FacebookAccess
因为它已经很旧了。它早于原生FacebookConnect
API。这里有这个示例:https ://www.codenameone.com/blog/building-a-chat-app-with-codename-one-part-3.html
它包括使用图形 API 和令牌数据访问 facebook 的代码。这使用旧的图形 API 版本,因此您可能需要稍微更新语法,但要点保持不变。
推荐阅读
- php - AJAX 给出的结果与 MySQL 不同
- java - 检测应用程序是否从另一个活动返回到 MainActivity
- python - Python:如何跨多个数据库对多个查询进行多线程处理
- rust - `Iterator::inspect` 中的闭包的副作用是否定义良好,因此可以用于例如计数?
- python-3.x - 在一张图中绘制多个箱线图
- java - MTN 移动货币集成
- visual-c++ - 我需要帮助理解这个“for”循环
- amazon-web-services - AWS 上按 IP 阻止的安全组
- php - 将两个对象合并为一个数组
- javascript - 在javascript中过滤两个对象数组