Spring Facebook模板将fetchObject映射到PagedList [英] Spring Facebook Template map fetchObject to PagedList
问题描述
我正在使用以下方法返回Facebook用户的音乐偏好:
I'm using the following approach to return a Facebook user's music preferences:
//FIXME: Fetch results in a single operation
val likes = facebook.likeOperations().music
val artists = ArrayList<Artist>()
for (musicLiked in likes)
{
val musicProfile = facebook.fetchObject(musicLiked.id, Page::class.java, "id", "name", "genre");
artists.add(Artist(name = musicProfile.name, genre = musicProfile.genre))
}
以上方法无法扩展,因为我们为用户喜欢的每个艺术家提供了额外的网络操作.
The above approach won't scale, since we have an additional network operation for each artist the user likes.
我尝试过:
我尝试使用facebook.likeOperations.music
,但这不能获取类型.
I tried using facebook.likeOperations.music
however this doesn't fetch genre.
问题:
我想在返回PagedList
的查询中使用facebook.fetchObject
.这该怎么做?
I would like to use facebook.fetchObject
with a query that returns a PagedList
. How to do this?
(如果您更喜欢或更熟悉Java,则无需在Kotlin中发布示例代码-我将对使用任何语言的信息感到满意).
推荐答案
由于@burovmarley的回答中给出的建议,我检查了源代码并提出了:
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}")
}
这允许将Spring Social Facebook用作未修改的依赖项,而无需发出请求,这在当前队列中的处理中似乎相当慢.
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.
这篇关于Spring Facebook模板将fetchObject映射到PagedList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!