Retrieve the user profile image from twitter

12,907

Solution 1

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);

Solution 2

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

Share:
12,907
AhmadAssaf
Author by

AhmadAssaf

I am a creative enthusiast who always seeks new ideas and technologies and aims to enhance work efficiency and increase my knowledge, I am able to balance competing priorities and tight deadlines with quality, I am able to develop and deliver plans, create new ideas and find market niches. I am a fast learner who cannot get enough of learning; I have excellent analytical skills and keen to work under pressure. I am always keen to work in different projects especially those who allow me the chance to learn.

Updated on June 11, 2022

Comments

  • AhmadAssaf
    AhmadAssaf almost 2 years

    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);
    

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

  • AhmadAssaf
    AhmadAssaf over 13 years
    thanks for the answer, but how can show the image in a Jlabel for example ? can it be casted bufferd image ?
  • A-Live
    A-Live over 11 years
    getProfileImage should not be used as the image source.