package weibo4j.examples.friendships;
import weibo4j.Friendships;
import weibo4j.examples.oauth2.Log;
import weibo4j.model.User;
import weibo4j.model.UserWapper;
import weibo4j.model.WeiboException;
public class GetFollowersById {
public static void main(String[] args) {
String access_token = "";
String uid = "1706206925";
Friendships fm = new Friendships();
fm.client.setToken(access_token);
try {
UserWapper users = fm.getFollowersById(uid);
int cursor = 0;
int count = (int) users.getTotalNumber();
while (cursor < count) {
users = fm.getFollowersById(uid, 10, cursor);
for (User u : users.getUsers()) {
Log.logInfo(u.toString());
}
cursor = (int) users.getNextCursor();
System.out.println(cursor);
}
System.out.println(users.getNextCursor());
System.out.println(users.getPreviousCursor());
System.out.println(users.getTotalNumber());
}
catch (WeiboException e) {
e.printStackTrace();
}
}
}
新浪微博的api写得就是一渣渣!用新浪微博的有病!抵制!
public static void main(String[] args) {
String access_token = "";
String uid = "1706206925";
Friendships fm = new Friendships();
fm.client.setToken(access_token);
final int pageSize = 30;
try {
UserWapper users = fm.getFollowersById(uid);
users.setNextCursor(0);
do {
System.out.println(users.getNextCursor());
users = fm.getFollowersById(uid, pageSize, (int) users.getNextCursor());
for (User u : users.getUsers()) {
Log.logInfo(u.toString());
}
System.out.println(users.getPreviousCursor());
System.out.println(users.getNextCursor());
System.out.println(users.getTotalNumber());
} while (users.getNextCursor() != 0);
}
catch (WeiboException e) {
e.printStackTrace();
}
}
初始化设置getNextCursor = 0,每次获取30
第一次
getPreviousCursor():0
getNextCursor():30
第二次
getPreviousCursor():0
getNextCursor():60
第三次
getPreviousCursor():0
getNextCursor():90
第四次
getPreviousCursor():0
getNextCursor():0
我的好友有92,实际获取到的只有80,据说有些可能是僵尸粉被拦截了