Trying to retrieve all marketing accounts of a Facebook business account using the spring social framework for Facebook .
- I want to know if there is any better way to it other than what i did below ?
- Does what i did for paging the query result is the right way to do it ?
- Is there another way to retrieve data from the Facebook Marketing API ?
I really appreciate any help you can provide.
public List<String> getListAdAccountsId(String businessAccountId) {
final List<String> accountsId = new ArrayList<String>();
final MultiValueMap<String, String> queryParameters = new LinkedMultiValueMap<String, String>();
queryParameters.add("fields", "account_id");
queryParameters.add("offset", "0");
PagedList<Map> pagedResultSubSet = facebook.fetchConnections(businessAccountId, "adaccounts", Map.class,
queryParameters);
do {
queryParameters.set("offset", pagedResultSubSet.getNextPage().getOffset().toString());
pagedResultSubSet = facebook.fetchConnections(businessAccountId, "adaccounts", Map.class, queryParameters);
accountsId.addAll(pagedResultSubSet.parallelStream().map(e -> e.get("id").toString())
.collect(Collectors.toList()));
} while (pagedResultSubSet.getNextPage() != null);
return accountsId;
}