如何获取超过 25 条帖子
我正在尝试使用restfb获取所有帖子消息,我的代码如下
public Connection<Post> publicSearchMessages(Date fromDate, Date toDate) {
Connection<Post> messages = publicFbClient.fetchConnection("search",
Post.class,
Parameter.with("q", "Watermelon"),
Parameter.with("since", fromDate),
Parameter.with("until", toDate),
Parameter.with("type", "post"));
return messages;
}
这仅提供最新的25条帖子消息。
Parameter.with("limit",100)
如果我设置 limit 参数,它会给出 100 条消息,但我不想限制为获取帖子消息。那么,
我是否可以在不设置限制参数的情况下获得符合搜索条件的帖子消息的完整列表?
I'm trying to get all post messages using restfb, my code is as follows
public Connection<Post> publicSearchMessages(Date fromDate, Date toDate) {
Connection<Post> messages = publicFbClient.fetchConnection("search",
Post.class,
Parameter.with("q", "Watermelon"),
Parameter.with("since", fromDate),
Parameter.with("until", toDate),
Parameter.with("type", "post"));
return messages;
}
This only gives latest 25 post messages.
Parameter.with("limit",100 )
If i set limit parameter, it gives 100 messages but i don't want to limit to fetching post messages. So,
Is there anyway I can get a full list of post messages matching the search criteria without setting limit parameter?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许你可以尝试使用循环。 FB 每次无法获取超过 1000 个,因此您可以使用循环来获取整个 feed。像这样使用偏移量:
Offset 将是一个变量,其值将是 1000,2000,3000...
Maybe you can try using a loop. FB can't get more than 1000 each time, so you can use the loop to get the whole feeds. Use the offset like this:
Offset will be a variable and its value will be 1000,2000,3000...
无法从 FB 获取无限的结果。默认限制设置为 25。如您所知,您可以使用
limit
参数更改此设置。我还没有找到限制网络搜索的上限。也许,您可以将其设置为非常高的金额。There is no way to fetch unlimited results from FB. The default limit is set to 25. As you know, you can change this using the
limit
parameter. I have not found an upper border for limit searching the web. Maybe, you can set it to a very high amount.正如我最近测试的那样,您不必指定任何内容。 Connection 类以这种方式实现 Iterable:
所以基本上你需要做的就是这样:
如果你想要某种方法返回结果我会非常小心,因为您可能会返回数千个结果,并且爬行它们可能需要一些时间(从几秒到几分钟甚至几小时),并且结果对象数组将非常大。更好的想法是使用一些异步调用并定期检查方法的结果。
尽管似乎参数“since”被忽略了。帖子是从最新到最旧的顺序获取的,我认为它在进行分页时以某种方式遗漏了这个参数。
希望我对你说得更清楚:)
As I tested recently, You don't have to specify anything. Connection class implements Iterable in this way:
So basically all you need to do is this:
If you want to have some kind of method that returns results I would be very careful, because you can be returning thousands of results and crawling through them may take some time (from seconds to minutes or even hours) and result object array is going to be really big. Better idea is to use some asynchronous call and check out results of method periodically.
Though it seems that parameter "since" is ignored. Posts are fetched from newest to oldest and I think that it somehow leave out this parameter when doing paging.
Hope I made it more clear for you :)
我们在 Post 中有一个 Iterator 对象。所以我们可以这样做:
然后在每条消息中我们将有接下来的 25 条消息。
We have an Iterator object in Post. So we can do it like this:
Then in each messages we'll have next 25 messages.