Retrieve the user profile image from twitter

前端 未结 2 703
天涯浪人
天涯浪人 2020-12-09 06:27

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.getProfileImag         


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-09 06:53

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

提交回复
热议问题