如何在android中的twitter集成中获取用户个人资料图片?
问题描述:
嗨, 我是新来的机器人尝试整合Twitter与我的应用程序。我需要在用户登录后获取Twitter个人资料名称和个人资料图片。我可以获取个人资料名称,但不能显示个人资料图片。我如何获取个人资料照片?如何在android中的twitter集成中获取用户个人资料图片?
答
如果您提取了user profile,请查看名为“profile_image_url”的json条目。有些关于此的twitter文档也可以找到here。将此与ImageDownloader一起使用,以下载要在项目中用作位图的图像。这是如何下载和显示图像的头号谷歌的结果:
http://getablogger.blogspot.com/2008/01/android-download-image-from-server-and.html
答
private TwitterApp mTwitter;
mTwitter.getUserProfileImage();
返回登录的用户的个人资料照片。
也ü可以定制根据事先知情同意是指:Android Twitter getting profile image size issue
答
你可以得到这样一些信息:
TwitterApiClient twitterApiClient = TwitterCore.getInstance().getApiClient();
twitterApiClient.getAccountService().verifyCredentials(false, false, new Callback<User>() {
@Override
public void success(Result<User> userResult) {
String name = userResult.data.name;
String email = userResult.data.email;
// ... other infos
// Get the profile pic
// _normal (48x48px) | _bigger (73x73px) | _mini (24x24px)
String photoUrlNormalSize = userResult.data.profileImageUrl;
String photoUrlBiggerSize = userResult.data.profileImageUrl.replace("_normal", "_bigger");
String photoUrlMiniSize = userResult.data.profileImageUrl.replace("_normal", "_mini");
String photoUrlOriginalSize = userResult.data.profileImageUrl.replace("_normal", "");
}
@Override
public void failure(TwitterException exc) {
Log.d("TwitterKit", "Verify Credentials Failure", exc);
}
});
从官方文档:
您可以获取用户的最近的个人资料图片来自
GET users/show
。在用户对象中,您可以找到profile_image_url
和profile_image_url_https
字段。这些字段将包含用户上传图像的调整大小的“正常”变体的 。这个“正常的” 变体通常是48x48px。通过修改URL,您可以检索其他变体尺寸,例如 “更大”,“迷你”和“原始”。
我已经给出了答案, 找到你的答案[here](http://stackoverflow.com/a/39632369/2623882) –