OVERVIEW

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).

SOLUTION

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:

5.  Create Config

6.  Add Twitter login button under XML file

7.  Find Twitter login button under class

8.  Add Callback to Twitter button

9.  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.

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

11.  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.

Read also:

• Template App vs. Custom App: What’s the Difference?

• How to Integrate Siri in Your iOS App

Native vs Cross Platform App Development

Rate:
How to Add and Change Twitter Profile Picture From Android App
5 based on 5 user ratings