如何在 twitter4j 中将推特 ID 转换为用户名?或者我可以使用 id 来获取用户简介吗?
How do turn twitter IDs to Username in twitter4j? Or can I use id to get a user bio?
所以我从
得到了一堆ID
do {
if (0 < SklsIds.length) {
ids = twitter.getFriendsIDs(identlong, cursor);
} else {
ids = twitter.getFriendsIDs(cursor);
}
for (long id : ids.getIDs()) {
followers.add(id);
}
} while ((cursor = ids.getNextCursor()) != 0);
然后我想使用这些 ID 获取用户简介:
for (Long ideez : followers) {
System.out.println(twitter.showUser(ideez.toString()));
String bio = ideez.toString().getDescription().toLowerCase();
}
我有这个 rn,但我不认为你可以只用 id 或其他任何东西来获得用户的简介。请帮忙
我们可以做这样的事情来检索我们的 Twitter 用户朋友的姓名和简介:
try {
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
long cursor = -1;
IDs ids;
System.out.println("Listing followers's ids.");
do {
ids = twitter.getFriendsIDs(cursor);
// Retrieve the follower IDs into an array
long[] userIds = ids.getIDs();
// Iterate through the array in batches of 100. We need batches of 100 because lookupUser method accept at most 100 ids
for (int i = 0; i < userIds.length; i += 100) {
ResponseList<User> users = twitter.lookupUsers(Arrays.copyOfRange(ids.getIDs(), i, Math.min(i + 100, userIds.length)));
// Iterate through the users and retrieve information about them
for (User user : users) {
// Do something with the user name
System.out.println(user.getName());
// Do something with the bio description
System.out.println(user.getDescription());
}
}
} while ((cursor = ids.getNextCursor()) != 0);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get followers' ids: " + te.getMessage());
System.exit(-1);
}
所以我从
得到了一堆IDdo {
if (0 < SklsIds.length) {
ids = twitter.getFriendsIDs(identlong, cursor);
} else {
ids = twitter.getFriendsIDs(cursor);
}
for (long id : ids.getIDs()) {
followers.add(id);
}
} while ((cursor = ids.getNextCursor()) != 0);
然后我想使用这些 ID 获取用户简介:
for (Long ideez : followers) {
System.out.println(twitter.showUser(ideez.toString()));
String bio = ideez.toString().getDescription().toLowerCase();
}
我有这个 rn,但我不认为你可以只用 id 或其他任何东西来获得用户的简介。请帮忙
我们可以做这样的事情来检索我们的 Twitter 用户朋友的姓名和简介:
try {
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
long cursor = -1;
IDs ids;
System.out.println("Listing followers's ids.");
do {
ids = twitter.getFriendsIDs(cursor);
// Retrieve the follower IDs into an array
long[] userIds = ids.getIDs();
// Iterate through the array in batches of 100. We need batches of 100 because lookupUser method accept at most 100 ids
for (int i = 0; i < userIds.length; i += 100) {
ResponseList<User> users = twitter.lookupUsers(Arrays.copyOfRange(ids.getIDs(), i, Math.min(i + 100, userIds.length)));
// Iterate through the users and retrieve information about them
for (User user : users) {
// Do something with the user name
System.out.println(user.getName());
// Do something with the bio description
System.out.println(user.getDescription());
}
}
} while ((cursor = ids.getNextCursor()) != 0);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get followers' ids: " + te.getMessage());
System.exit(-1);
}