spring-attic / spring-social

Allows you to connect your applications with SaaS providers such as Facebook and Twitter.
http://projects.spring.io/spring-social
Apache License 2.0
619 stars 351 forks source link

Easier way to extend PageOperations #146

Open feribg opened 9 years ago

feribg commented 9 years ago

Currently all facebook PageOperations depend on the "access_token" to be present. This abstraction is handled in the PageOperations template which introduces a private cache and getter for page access tokens. The problem arises that:

Places I am having trouble with: For example PageOperations exposes the postPhoto(pageId, albumId, Resource) method, in order to use that one will have to first create an album in the given pageId. There doesn't seem to be a way to do that currently. MediaOperations.createAlbum creates it in the user's account and not under the page. There also doesn't seem to be an api to post directly to a page wall, which would seem like a much more common use case, then posting to an album (which can't be created programmatically currently). For example to post a photo to a page wall i have to write something like

Map<String, Account> accountCache = new HashMap<String, Account>();List<Account> accounts = facebook.pageOperations().getAccounts();
for (Account account : accounts) {
accountCache.put(account.getId(), account);
}
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
parts.set("source", imageResource);
parts.set("message", message);
parts.set("access_token", accountCache.get(facebookPageId).getAccessToken());
facebook.publish(facebookPageId, "photos", parts);

Notice that accountCache will be redundant. I read the API a few times, browsed over the code but didnt see a better way at doing it. What's your take on this?