简体   繁体   English

Android - Fabric.io Twitter REST API个人资料图片/图片

[英]Android - Fabric.io Twitter REST API profile image / picture

Does anyone know if there is a way to pull a signed in users profile picture to be placed through the app, to maybe place it on the ActionBar as they navigate around? 有没有人知道是否有办法通过应用程序提取已签名的用户个人资料图片,以便在他们浏览时将其放在ActionBar上?

hints, tips, examples, downloads all welcome :) 提示,提示,示例,下载都欢迎:)

If you can help me, please assume I very little knowledge regarding anything outside basic Java! 如果你可以帮助我,请假设我对基本Java之外的任何东西都知之甚少!

Again, thanks people x 再次,谢谢人们x

You can get a user's profile image by using /1.1/users/show.json . 您可以使用/1.1/users/show.json获取用户的个人资料图像。 You can refer to REST API URLs for Twitter data. 您可以参考Twitter数据的REST API URL

By extending TwitterApiClient we can retrieve Twitter data from the URL. 通过扩展TwitterApiClient我们可以从URL中检索Twitter数据。

class MyTwitterApiClient extends TwitterApiClient {
    public MyTwitterApiClient(TwitterSession session) {
        super(session);
    }

    public UsersService getUsersService() {
        return getService(UsersService.class);
    }
}

interface UsersService {
    @GET("/1.1/users/show.json")
    void show(@Query("user_id") Long userId,
            @Query("screen_name") String screenName,
            @Query("include_entities") Boolean includeEntities,
            Callback<User> cb);
}

Next, get the UsersService and call its show method, passing in the defined query parameters. 接下来,获取UsersService并调用其show方法,传入已定义的查询参数。 I defined the query parameters based on the ones that are documented. 我根据记录的参数定义了查询参数。

new MyTwitterApiClient(session).getUsersService().show(12L, null, true,
new Callback<User>() {
    @Override
    public void success(Result<User> result) {
        Log.d("twittercommunity", "user's profile url is "
                + result.data.profileImageUrlHttps);
    }

    @Override
    public void failure(TwitterException exception) {
        Log.d("twittercommunity", "exception is " + exception);
    }
});

Courtesy: https://twittercommunity.com/t/android-get-user-profile-image/30579/2 礼貌: https//twittercommunity.com/t/android-get-user-profile-image/30579/2

This is how I got mine to work: 这就是我开始工作的方式:

            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 profilebannerurl = userResult.data.profileBannerUrl;
                    String profileurl = userResult.data.profileImageUrl;

                }

                @Override
                public void failure(TwitterException e) {

                }
            });

I have place this piece of code within my LoginButton callback method: 我将这段代码放在我的LoginButton回调方法中:

    loginButton.setCallback(new Callback<TwitterSession>() {
        @Override
        public void success(Result<TwitterSession> result) { <insert here> }

I did it with a custom button and this is the code that is executed by it's onClick listener : 我用自定义按钮做了这个,这是由它的onClick监听器执行的代码:

TwitterAuthConfig authConfig =  new TwitterAuthConfig(TWITTER_API_KEY, TWITTER_API_SECRET);
Fabric.with(activity, new Twitter(authConfig));

TwitterCore.getInstance().getApiClient().getAccountService().verifyCredentials(false, false, new com.twitter.sdk.android.core.Callback<User>() {
    @Override
    public void success(Result<User> result) {
        Log.d(TAG, "Twitter log in success");

        String userName = result.data.screenName;
        int userId = result.data.id;
        String pictureUrl = result.data.profileImageUrl;
        String coverUrl = result.data.profileBannerUrl;
    }

    @Override
    public void failure(TwitterException e) {
        Log.d(TAG, "Twitter log in error : " + e.getMessage());
    }
});

I should ask the user to authorize access to your app and log him in if he accepts. 我应该要求用户授权访问您的应用并在他接受时登录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM