Hello,
Are you wanting to get the profile image of the logged in user? If so, you can get this by calling AccountServices#verifyCredentials(), which will return the user object associated with the specified TwitterSession.
However, if you want to get the profile image of any Twitter user, there isn’t a method out of the box that allows you to do this. You’ll need to extend the TwitterApiClient to add additional Twitter authenticated endpoints. Below is an example of how you can get a user’s profile image by using the /1.1/users/show.json endpoint.
First, extend the TwitterApiClient to provide a UsersService.
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. I defined the query parameters based on the ones that are documented here.
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);
}
});
Hope this helps!