android - 如何使用 Twitter 套件在 Android 中获取个人资料图片,

标签 android image twitter

我正在尝试实现一个使用 Twitter 工具包的简单应用程序。问题是我无法获取个人资料图片。我们将不胜感激。

谢谢

最佳答案

来自官方文档:

You can obtain a user’s most recent profile image from GET users/show. Within the user object, you’ll find the profile_image_url and profile_image_url_https fields. These fields will contain the resized “normal” variant of the user’s uploaded image. This “normal” variant is typically 48x48px.

By modifying the URL, you can retrieve other variant sizings such as “bigger”, “mini”, and “original”.

代码如下:

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;

        // _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);
    }
});

有关更多信息,请参阅 Twitter API Documentation | Profile Images and Banners

关于android - 如何使用 Twitter 套件在 Android 中获取个人资料图片,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27930527/

相关文章:

image - 在 Magento 中以编程方式将图像设置为类别

php - 在没有ImageMagick的情况下在PHP中将PDF转换为图像

android - 模块库 Android Studio 上的 Twitter Kit Fabric Android

android - 将 Android 项目添加为库 (SlidingMenu) 时出现 Gradle 错误 [包不存在]

android - 我如何替换android中gridview中的单个图像?

CSS在div中定位两个图像

node.js - 如何使用同一 Twitter 应用程序对来自一个域的多个主机名进行 Twitter 身份验证?

python - Redis 与 Twemproxy 对比 memcached

java - 使用Android获取异步任务JSON时出现空指针异常

Android 模拟器以华丽的 'Android' 启动,但应用程序从未启动,我看不到任何主屏幕