Main objective of Twitter Integration tutorial is to explain how to integrate Twitter with Android Application.


You will get Final Output:


In this blog, I’ll integrate Twitter in one demo app and post an image from that app to my twitter account.

Following are the steps to Integrate Twitter in your Android application:


Step 1 Create an App on

First of all you have to create the twitter application id & secrets. Links is given below. When you open this link page is look link below snapshot. Provide necessary information to create your ID.

create an application

developer agreement


Step 2 Setting Access Level

After creating your Twitter App. Now you have to set the access level for your app. There are three options for setting level.

Read Only Select this permission if you want to only read the data and don’t want to post anything.
Read & Write Select this permission if you want to read as well as post the data.
Read, Write & Acess direct messages This permission will allow an application to read or delete a user's direct messages.


application settings

Note: Copy this consumer Key and secret to somewhere for future use.


Step 3 Create an Android Project

After completing above steps. Open your Eclipse and Create new Android Application Project in Eclipse. Here path is given File >> New >> Android Application Project



Step 4 Create XML Layout

Now create xml layout in res folder with name activity_main.xml and create your custom xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
    android:orientation="vertical" >
        android:orientation="vertical" >
            android:src="@drawable/ic_launcher" />
        android:orientation="vertical" >
            android:ems="10" >
            <requestFocus />
        android:text="@string/btn_Post" />

After write above code in file screen is look like:

post on twitter


Step 5 Integrate .jar files

You need to integrate two jar files in order to integrate Twitter in your project

  1. socialauth-4.4.jar
  2. socialauth-android-3.2.jar

You can download this .jar files from given link:


Step 6 Put .jar files

Put these .jar files in libs folder. Shows in the blow screenshot.

putting jar


Step 7 Twitter Consumer Key

Referencing key and secret in the application After placing the social-auth.jar create file in asset folder and in this file set Twitter consumer key & secrets in it like below. From this file key is directly used by social auth library and we don’t need to give any static reference to it.

#twitter = "consumer_key" = "consumer_secret"

Now open file and put these two statements there

socialAuthAdapter = new SocialAuthAdapter(new ResponseListener(((BitmapDrawable)ivUploadImage.getDrawable()).getBitmap(),etMessage.getText().toString()));
socialAuthAdapter.addProvider(Provider.TWITTER, R.drawable.twitter);	socialAuthAdapter.authorize(MainActivity.this, Provider.TWITTER);
  • device-screenshot
  • device-screenshot-1

Step 8 ResponseListener class for Authorization

Create ResponseListener class. This class handles the authorization result which says whether the user is authorized or not.

There are 4 methods in the class, which does the following tasks:

  • If authorized properly, then we get acknowledgement in onComplete() method.
  • If Error occurred during authorization, then we get acknowledgement in onError() method.
  • If User cancels the authorization dialog box, then we get acknowledgement in onCancel() method
  • If user press back button of the device, then we get acknowledgement in onBack() method
private class ResponseListener implements DialogListener {
Bitmap bitmap;
String message;
public ResponseListener(Bitmap bitmap, String message) {
this.bitmap = bitmap;
this.message = message;
public void onComplete(final Bundle values) {
try {
socialAuthAdapter.uploadImageAsync(message, "The AppGuruz.png",
bitmap, 100, new UploadImageListener());
} catch (Exception e) {
public void onError(SocialAuthError error) {
if (pd != null && pd.isShowing())
Log.d("ShareTwitter", "Authentication Error: " + error.getMessage());
public void onCancel() {	
Log.d("ShareTwitter", "Authentication Cancelled");
public void onBack() {
Log.d("ShareTwitter", "Dialog Closed by pressing Back Key");

Step 9 UploadImageListener Class

After getting the response of authorization from Twitter, call UploadImageListener to upload image and status message. UploadImageListener class uploads the image to user’s Twitter account.

private final class UploadImageListener implements
SocialAuthListener {
public void onError(SocialAuthError e) {
public void onExecute(String arg0, Integer arg1) {
Integer status = arg1;
try {
if (status.intValue() == 200 || status.intValue() == 201
|| status.intValue() == 204) {
Toast.makeText(MainActivity.this, "Image Uploaded",
} else {
Toast.makeText(MainActivity.this, "Image not Uploaded",
} catch (NullPointerException e) {
Toast.makeText(MainActivity.this, "Image not Uploaded",



Step 10 Check your Twitter Account

Finally you can check that your image and status message has been successfully posted on the Twitter Account.

I hope you found this blog helpful while integrating Twitter in your application. Let me know if you have any questions or concerns, please put a comment here and we will get back to you ASAP.

Got an Idea of Android App Development? What are you still waiting for? Contact us now and see the Idea live soon. Our company has been named as one of the best Android App Development Company in India.

I am professional Android application developer with experience of 1 years in Android Application Development. I worked with so many technology but android is the only one which interests me.