Spring Facebook Template map fetchObject to PagedList

不想你离开。 提交于 2019-12-06 11:32:33

Facebook api uses "fields" parameter in requests to return custom fields for objects. This parameter can be also used for liked music rest request.



    me/music?fields=id,genre,name

above link will return all liked music with id, genre and name of the artist/group. Unfortunately FacebookTemplate does not have method which will apply for your needs. The method Facebook.likeOperations() returns instance of the LikeTemplate class which has constant PAGE_FIELDS with value



    private static final String PAGE_FIELDS = "id,name,category,description,location,website,picture,phone,affiliation,company_overview,likes,checkins";

In above constant you do not have genre field. So you have two ways:

  1. You can simply use facebook rest api with some rest library
  2. You can override FacebookTemplate and return your own implementation of LikeTemplate as result of the likeOperations() method. You implementation of the LikeTemplate class should have different value in mentioned constant (added genre field at the end of the string)

Maybe some one will be more helpful but in my knowledge you do not have other options.

Thanks to advice given in @burovmarley's answer, I inspected the source and came up with:

val music = facebook.fetchConnections(userPage.id, "music", Page::class.java,
            PagingParameters(25, 0, null, null).toMap(), "id,name,,genre")
for (musicLiked in music)
{
    println("likes: ${musicLiked.name}, genre: ${musicLiked.genre}")
}

This allows using Spring Social Facebook as an unmodified dependency, and without issuing a pull request, which seem to be fairly slow in processing through the queue at the present time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!