1

作为开发人员,我是新手,正在尝试 Spring 社交 facebook 集成。关注了这个链接

我正在获取诸如用户名、“性别”、“语言环境”之类的数据。可以将其作为构造函数值提供给 User 类(请参阅帮助)。

但我想获取用户“电子邮件 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.
4

0 回答 0