总结新浪friendship接口

 

总结新浪friendship接口


1.好友和粉丝的上限(双向关注):5000,不管是取详情还是取id.

http://forum.open.weibo.com/read.php?tid=67480
http://forum.open.weibo.com/read.php?tid=70622


1.1如果取ids


https://api.weibo.com/2/friendships/friends/bilateral/ids.json


单页返回的记录条数[0~2000],默认为50,可调


            String[] ids = fm.getFriendsBilateralIds(id);
            //打出的值仍然是50,所以不要认为通过id取就能取回全部。
            System.out.println("互粉用户数:"+ids.length);



https://api.weibo.com/2/friendships/friends/ids.json   or https://api.weibo.com/2/friendships/followers/ids.json

单页返回的记录条数[0~5000],默认为500,可调

同理,其它接口获取ids,返回的也不是全部,默认是500
            ids = fm.getFriendsIds(id);
            //500
            System.out.println("我粉的用户数:"+ids.length);
            
            ids = fm.getFollowersIdsById(id);
            //500
            System.out.println("粉我的用户数:"+ids.length);


1.2如果取的是详情,比如List<User>

使用的地址如下:通常由于我们需要用户的额外信息,所以,下面二个地址是分页获取的主要方式。
http://open.weibo.com/wiki/2/friendships/friends  or http://open.weibo.com/wiki/2/friendships/followers

单页返回的记录条数是[0~200],默认为50,可调。

另,qq的授权请求次数是1000,qq的取id每页最高200。


2.不要通过API的注释去理解功能。而应熟悉URL对应的文档。

3. 如果API不存在的时候,根据url尝试封装相应的接口方法去尝试


比如取关注的人,只提供了

    public List<User> getFriendsByID(String id) throws WeiboException
    {
        return User.constructUser(Weibo.client.get(WeiboConfig.getValue("baseURL") + "friendships/friends.json",
                                                   new PostParameter[] { new PostParameter("uid", id) }));
    }

实际肯定需要分页获取用户的信息,封装如下:


    public List<User> getFriendsById(String uid, Integer count, Integer cursor) throws WeiboException
    {
        return User.constructUser(Weibo.client.get(WeiboConfig.getValue("baseURL") + "friendships/friends.json",
                                                   new PostParameter[] {
                                                           new PostParameter("uid", uid),
                                                           new PostParameter("count", count.toString()),
                                                           new PostParameter("cursor", cursor.toString()) }));
    }

附:论坛上新浪的管理员也建议这样做。

原文地址:https://www.cnblogs.com/highriver/p/2556447.html