从twitter检索用户个人资料图片

问题描述:

我正在使用Java中的Twitter4J API来检索登录的Twitter用户的个人资料图片。该命令类似于:

I am using the Twitter4J API in Java to retrieve the profile image for a Twitter user whose logged in. The command is something like :

twitter.getProfileImage(twitter.getScreenName(), Imagesize);

图像尺寸是多少?如何在标签中显示 ProfileImage 对象?

What is the image size? How can I display the ProfileImage object in a label for example?

好的,答案是:

假设Twitter对象是推特

Assume that the Twitter object is twitter

1 - 从中​​获取用户twitter对象

1 - get the user from the twitter object

User user = twitter.showUser(twitter.getid());

2 - 获取个人资料图片网址

2 - get the profile image URL

URL url = user.getProfileImageURL();

3 - 创建图像图标

3 - create Image icon

ImageIcon img = new ImageIcon(url);

4 - 将JLabel图标设置为ImageIcon

4 - set the JLabel icon to be the ImageIcon

Jlabel1.setIcon(img);