java 从 Twitter 检索用户个人资料图片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4606790/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Retrieve the user profile image from twitter
提问by AhmadAssaf
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 :
我在 Java 中使用 Twitter4J API 来检索已登录的 Twitter 用户的个人资料图像。命令类似于:
twitter.getProfileImage(twitter.getScreenName(), Imagesize);
What is the image size? How can I display the ProfileImage
object in a label for example?
图像大小是多少?例如,如何ProfileImage
在标签中显示对象?
回答by AhmadAssaf
ok, the answer is :
好的,答案是:
Assume that the Twitter object is twitter
假设 Twitter 对象是 twitter
1 - get the user from the twitter object
1 - 从 twitter 对象中获取用户
User user = twitter.showUser(twitter.getid());
2 - get the profile image URL
2 - 获取个人资料图片 URL
URL url = user.getProfileImageURL();
3 - create Image icon
3 - 创建图像图标
ImageIcon img = new ImageIcon(url);
4 - set the JLabel icon to be the ImageIcon
4 - 将 JLabel 图标设置为 ImageIcon
Jlabel1.setIcon(img);
回答by YAMAMOTO Yusuke
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
您可以传递 ProfileImage.MINI、ProfileImage.NORMAL 或 ProfileImage.BIGGER