Easy to change profile photo

Quick Solution for Adding and Changing Twitter Profile Picture From Android App

Easy to change profile photo



One of our clients sent us a request to deliver Facebook and Twitter integration for both iOS and Android platforms.  Facebook and Twitter change their API very often and due to the latest changes, it was not obvious how to do that quickly on Android platform, and there was no well-structured documentation on Twitter API for adding and changing Twitter Profile picture from 3rd party Android app.

iOS has an easy option to add or change user profile icon via Twitter API under native SDK.  For Android, here is what we have under Twitter API docs https://docs.fabric.io/android/twitter/access-rest-api.html#extensions and there is no clear code example with POST request for REST API.

Twitter changed REST API (previously it was written for Eclipse IDE) and currently under Android Studio IDE it is working with Fabric, but steps and code for integration Fabric for quick login were not described in full and it appeared that there was no easy and quick way to do that.

Here we are glad to describe Steps On How to Change User Avatar/on User Profile from mobile app (Android).

And we did it. Here I am happy to share more details on how we resolved that (in code).


For proper Twitter integration we have to start from the following steps

  1. Integrate Fabric into Android Studio
  2. Register App under Fabric
  3. Receive Consumer Key (API Key) and Consumer Secret (API Secret)
  4. Under project you should add the following:

  1. Create Config

  1. Add Twitter login button under XML file

  1. Find Twitter login button under class

  1. Add Callback to Twitter button

  1. Create class to upload User picture

Please check the following link for the reference:  http://square.github.io/retrofit/.

Here the 1st parameter for sendPhoto method is User ID, the 2d parameter is picture itself, base64. Tips and Tricks here: we would highly recommend compressing image, thus allowing to minimize time that query might take. Also this step also helps us to avoid getting Twitter warning regarding image size.

  1. Class received under Step 8 (described above) we transfer into our new class

  1. Ta-Daaah, you are welcome to run project and check results

SUCCESS!  From now your app can add and change User Profile picture under Twitter successfully.

We will be happy to send you Android demo video under request.

Source code. Source code is available from here Github

If you have questions please contact us