如何从Facebook获取用户照片
How to get user photo from facebook
当我在spring-boot应用程序中通过facebook注册用户时,如何立即从facebook获取他的照片?我需要获取当前用户照片并将此照片设置到数据库
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";
}
}
当我在spring-boot应用程序中通过facebook注册用户时,如何立即从facebook获取他的照片?我需要获取当前用户照片并将此照片设置到数据库
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";
}
}