【发布时间】:2014-01-10 03:23:30
【问题描述】:
我写了以下java代码:-
public static void main(String[] args) throws TwitterException, IOException {
//FROM HERE
Twitter twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("i use my keys here", "i use my keys");
RequestToken requestToken = twitter.getOAuthRequestToken();
AccessToken accessToken = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
while (null == accessToken) {
System.out.println("Open the following URL and grant access to your account:");
System.out.println(requestToken.getAuthorizationURL());
System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
String pin = br.readLine();
try{
if(pin.length() > 0){
accessToken = twitter.getOAuthAccessToken(requestToken, pin);
}else{
accessToken = twitter.getOAuthAccessToken();
}
} catch (TwitterException te) {
if(401 == te.getStatusCode()){
System.out.println("Unable to get the access token.");
}else{
te.printStackTrace();
}
}
}
IDs frndlst = twitter.getFollowersIDs(1);
long idlist[] = frndlst.getIDs();
for(int i=0;i<idlist.length;i++)
{
System.out.println(idlist[i]);
}
//TO HERE CO IS WORKING
//HERE I AM TRYING TO GET IDS OF MY FOLLOWERS BUT ITS NOT WORKING
System.out.println(idlist.toString());
System.out.println();
System.out.println(frndlst);
//HERE AGAIN I AM TRYING BUT STILL NOT WORKING
PagableResponseList<User> l1 = twitter.getFollowersList("varun_karhadkar", 10);
System.out.println("checking if empty"+ l1.isEmpty());
System.out.println(l1);
System.exit(0);
}
}
需要一些帮助,我想做的就是获取所有关注我的用户的屏幕名称以及我关注的所有用户的列表。
执行上述代码后的输出:-
Open the following URL and grant access to your account:
https://api.twitter.com/oauth/authorize?oauth_token=vXrXa5eaDMkTNd66bInW7e6u7WMX1yGiLmSD9h4
Enter the PIN(if aviailable) or just hit enter.[PIN]:9045949
[J@694bc02d
IDsJSONImpl{ids=[], previousCursor=-1, nextCursor=0}
checking if empty true
【问题讨论】: