Spring Social中的朋友和关注者 [英] Friends and Followers in Spring Social

查看:119
本文介绍了Spring Social中的朋友和关注者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用spring-integration-twitter 4.1.6.RELEASE.我正在使用TwitterTemplate尝试为经过身份验证的用户获取所有朋友.

I'm using spring-integration-twitter 4.1.6.RELEASE in my project. Using TwitterTemplate I was trying to get all the friends for the authenticated user.

因此我正在使用此方法,

So im using this method for it ,

friendsList = twitterTemplate.friendOperations().getFriends();

但是在这种情况下,我默认只有20个朋友.但是我有33个朋友,我想全部拿走.我该怎么做.调用此方法时,我也是经过身份验证的用户.在TwitterTemplate中,无法将计数作为参数传递.但是API表示它将返回5000个用户.

But in this case I'm only getting 20 friends as a default count. But I have 33 friends and I want to fetch them all. How can I do this.Also I'm a authenticated user when I call this method. In the TwitterTemplate there is no way to pass the count as a parameter. But the API says it will return 5000 users.

/** * Retrieves a list of up to 5000 users that the authenticated user follows. * Note that this method make multiple calls to Twitter's REST API (one call to get a list of the friend IDs and one call for every 100 friends). * If all you need is the friend IDs, consider calling getFriendIds() instead. * Or if you need only a subset of the user's friends, call UserOperations.getUsers() passing in the list of friend IDs you need. * @return a list of TwitterProfiles * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials. */ CursoredList<TwitterProfile> getFriends();

/** * Retrieves a list of up to 5000 users that the authenticated user follows. * Note that this method make multiple calls to Twitter's REST API (one call to get a list of the friend IDs and one call for every 100 friends). * If all you need is the friend IDs, consider calling getFriendIds() instead. * Or if you need only a subset of the user's friends, call UserOperations.getUsers() passing in the list of friend IDs you need. * @return a list of TwitterProfiles * @throws ApiException if there is an error while communicating with Twitter. * @throws MissingAuthorizationException if TwitterTemplate was not created with OAuth credentials. */ CursoredList<TwitterProfile> getFriends();

TwitterTemplate调用twitter API来获取数据.因此,请求重定向到Twitter API的https://api.twitter.com/1.1/friends/list.json访问URL.

TwitterTemplate calls the twitter API to fetch data. So request redirects to Twitter API's https://api.twitter.com/1.1/friends/list.json access URL.

Twitter API描述

目前,结果是按照最新的顺序排列的-但是,此顺序可能会发生未通知的更改和最终的一致性问题.结果以20个用户为一组给出,并且可以在后续请求中使用next_cursor值浏览结果的多个页面".有关更多信息,请参见使用光标导航集合.

At this time, results are ordered with the most recent following first — however, this ordering is subject to unannounced change and eventual consistency issues. Results are given in groups of 20 users and multiple "pages" of results can be navigated through using the next_cursor value in subsequent requests. See Using cursors to navigate collections for more information.

我该如何实现??

推荐答案

最终找到了解决方案,

1)首先,您必须使用friendOperations获取经过身份验证的用户的所有朋友ID列表.

1) First you have to get authenticated user's all friend Ids list using friendOperations.

2)然后使用userOperations获取特定ID列表的所有朋友.

2) Then get the all the friends for the particular id list using userOperations.

这是示例代码段,

List<org.springframework.social.twitter.api.TwitterProfile> friendsList;
CursoredList<Long> friendIdList;
long[] userIdArray;

friendIdList =  twitterTemplate.friendOperations().getFriendIds();
userIdArray = new long[friendIdList.size()];
for(int i=0; i<friendIdList.size(); i++)
    userIdArray[i] = friendIdList.get(i);
friendsList = twitterTemplate.userOperations().getUsers(userIdArray);

这篇关于Spring Social中的朋友和关注者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆