开发者

Retrieve the user profile image from twitter

I am using the Twitter4J API in Java to retrieve the profile 开发者_如何学Pythonimage for a Twitter user whose logged in. The command is something like :

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

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


ok, the answer is :

Assume that the Twitter object is twitter

1 - get the user from the twitter object

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

2 - get the profile image URL

URL url = user.getProfileImageURL();

3 - create Image icon

ImageIcon img = new ImageIcon(url);

4 - set the JLabel icon to be the ImageIcon

Jlabel1.setIcon(img);


Take a look at the example code. https://github.com/yusuke/twitter4j/blob/master/twitter4j-examples/src/main/java/twitter4j/examples/user/GetProfileImage.java

You can pass either ProfileImage.MINI, ProfileImage.NORMAL or ProfileImage.BIGGER

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜