Search code examples
javaandroidtwittertwitter4j

Get Twitter profile photo


I'm trying to create an interface of tweets with a special hashtag , and i want to add a profile photo picture in tweets , is there any way to get the twitter profile photo using twitter4j ?


Solution

  • Go through the following code.

    Assume that the Twitter object is mytTwitter
    *get the user from the twitter object
    
    User user = mytTwitter.showUser(mytTwitter.getid());
    
    *get the profile image URL
    
    URL url = user.getProfileImageURL();
    
    
    *create Image icon
    
    ImageIcon img = new ImageIcon(url);
    
    *set the JLabel icon to be the ImageIcon
    
    Jlabel1.setIcon(img);