My goal is to retrieve a list of events for a certain Facebook page and user profile. List should only return events in the future. I can’t seem to find a way with Spring Social Facebook API. I’m stuck with the following code.
Using Spring Social Facebook v3.0.0.M1
@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";
}
//Should only return events in the future
PagingParameters pagingParameters = new PagingParameters(10,0,0L,0L);
PagedList<Event> userEvents = facebook.eventOperations().search("noCriteriaNeed",pagingParameters);
PagedList<Event> pageEventfacebooks = facebook.pageOperations().facebookOperations("pageID").eventOperations().search("noCriteriaNeed",pagingParameters);
model.addAttribute("UserfacebookEvents", userEvents);
model.addAttribute("PagefacebookEvents", pageEventfacebooks);
return "hello";
}
}
2
Answers
I solved this by using the RestOperations API which is more flexible.
In addition to Siya’s answer here’s a simple implementation of the
EventData
class (just a List holding theEvent
objects):Furthermore, I found that one needs to specify the fields in the json response for more than a standard set to appear: