gpt4 book ai didi

java - 如何在Spring Social Twitter中获得超过20个好友?

转载 作者:行者123 更新时间:2023-11-30 07:05:50 26 4
gpt4 key购买 nike

我正在使用 Spring Social Twitter 检索用户 friend 的姓名。这是我的代码。

@Controller
@RequestMapping("/")
public class HelloController {

private Twitter twitter;

private ConnectionRepository connectionRepository;

@Inject
public HelloController(Twitter twitter, ConnectionRepository connectionRepository) {
this.twitter = twitter;
this.connectionRepository = connectionRepository;
}

@RequestMapping(method=RequestMethod.GET)
public String helloTwitter(Model model) {
if (connectionRepository.findPrimaryConnection(Twitter.class) == null) {
return "redirect:/connect/twitter";
}

model.addAttribute(twitter.userOperations().getUserProfile());
CursoredList<TwitterProfile> friends = twitter.friendOperations().getFriends();
model.addAttribute("friends", friends);
for ( TwitterProfile frnd : friends) {
System.out.println(frnd.getName());
}
return "hello";
}

}

但它只能检索到 20 个 friend 。我怎样才能得到所有的 friend ? (假设我有 1000 个 friend )

最佳答案

您必须遍历所有游标并按如下方式收集结果:

    // ...
CursoredList<TwitterProfile> friends = twitter.friendOperations().getFriends();
ArrayList<TwitterProfile> allFriends = friends;
while (friends.hasNext()) {
friends = twitter.friendOperations().getFriendsInCursor(friends.getNextCursor());
allFriends.addAll(friends);
}
// process allFriends...

关于java - 如何在Spring Social Twitter中获得超过20个好友?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26299466/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com