Android - Fabric.io Twitter REST API profile / image

Does anyone know if there is a way to pull out a signed user profile image that will be posted through the application so that it can possibly be placed in the ActionBar as they move?

hints, tips, examples, downloads of all greetings :)

If you can help me, suppose I know little about anything outside of basic Java!

Thanks again x people

+6
source share
3 answers

You can get a user profile picture using /1.1/users/show.json . You can refer to the REST API URLs for Twitter data.

By expanding TwitterApiClient , we can get Twitter data from a URL.

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

Then, start the UsersService and call its show method, passing in the specific request parameters. I determined the query parameters based on those documented.

 new MyTwitterApiClient(session).getUsersService().show(12L, null, true, new Callback<User>() { @Override public void success(Result<User> result) { Log.d("twittercommunity", "user 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

+9
source

Here is how I got my job:

  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 placed this piece of code in my LoginButton callback method:

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

I did this with a custom button, and this is the code that executes when I listen to it 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 have to ask the user to allow access to your application and log in if he agrees.

+1
source

Source: https://habr.com/ru/post/982449/


All Articles