[英]How to get user photo from facebook
When I register a user through facebook in spring-boot aplication, how to get his photo from facebook right away?当我在 spring-boot 应用程序中通过 facebook 注册用户时,如何立即从 facebook 获取他的照片? I need get current user photo and set this photo to database我需要获取当前用户照片并将此照片设置为数据库
After facebook Login success using Spring social library get the profile picture. facebook使用Spring社交库登录成功后获取头像。
@Controller
@RequestMapping("/")
public class MainController {
private Facebook facebook;
private ConnectionRepository connectionRepository;
public MainController(Facebook facebook, ConnectionRepository connectionRepository) {
this.facebook = facebook;
this.connectionRepository = connectionRepository;
}
@RequestMapping(value = "feed", method = RequestMethod.GET)
public String feed(Model model) {
if(connectionRepository.findPrimaryConnection(Facebook.class) == null) {
return "redirect:/connect/facebook";
}
byte[] profilePicture = facebook.userOperations().getUserProfileImage();
User userProfile = facebook.userOperations().getUserProfile();
model.addAttribute("userProfile", userProfile);
PagedList<Post> userFeed = facebook.feedOperations().getFeed();
model.addAttribute("userFeed", userFeed);
return "feed";
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.