我是开发人员,尝试Spring社交facebook集成。关注this link
我收到的信息包括用户名','性别','区域设置'。哪个可以作为User class的构造函数值给出(参见took help)。
但是我希望得到用户“email-id”,不知何故,我无法获得“名称”,“语言环境”和“性别”的数据。
我们需要根据文档使用方法getEmail()
。但我无法做到。
(“实施OAuth安全的简单应用”)
这是片段.... 我的控制器类代码是
@Controller
@RequestMapping("/")
public class HelloController {
private Facebook facebook;
private ConnectionRepository connectionRepository;
public HelloController(Facebook facebook, ConnectionRepository connectionRepository) {
this.facebook = facebook;
this.connectionRepository = connectionRepository;
}
@GetMapping
public String helloFacebook(Model model) {
if (connectionRepository.findPrimaryConnection(Facebook.class) == null) {
return "redirect:/connect/facebook";
}
String [] fields = {"name", "gender", "locale"};
User userProfile = facebook.fetchObject("me", User.class, fields);
model.addAttribute("feed", userProfile);
//String email = facebook.getEmail();
/*this above one "facebook.getEmail()" gives Internal server error 500 */
return "hello";
}
}
模型类是......
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8"/>
<title>Title</title>
</head>
<body>
<h3>Hello, <span th:text="${feed.name}">Some User</span>!</h3>
<h4>Your gender is : <span th:text="${feed.gender}"></span></h4>
<h4>Your locale is : <span th:text="${feed.locale}"></span></h4>
<h4>Your email is : <span th:text="${feed.getEmail()}"></span></h4>
</body>
</html>
主要课程是......
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Any help is appreciated. Thanks.