Post navigation

How to Integrate Twitter in your Android App

Among one thousand and one ways to push the graph of social engagement, we suggest integration of Twitter on Android. Considering its tremendous success, we have demonstrated below on how can your App be easily integrated with Twitter. Moreover, the sample also uses App42 Social Service API.

Topics Covered
1. How to create an App on Twitter & generate Consumer & Secret-Key
2. How to authenticate Twitter User with your android App
3. How to show Tweets along with user details
4. How to re-tweet the tweets again
5. How to update your Twitter status using App42 SocialService API

# Running Sample
1. Create a Twitter application to receive required keys
2. Once you have logged in your Twitter account, click on ‘Create button’ to make a new application
3. Find your Consumer Key and Secret Key here in ‘OAuth’ settings option
4. Now, Register with App42 platform
5. Once you are on Quick start page after registration, Create an app
6. If you are already registered, login to AppHQ console and create an app from App Manager Tab
7. Download the project from here and import it in the eclipse
8.Open Constants.java file and make the changes given below

1
2
3

A. Change CONSUMER_KEY with your Consumer key from step 5 at line no 7.
B. Change CONSUMER_SECRET with your Consumer secret from step 5 at line no 8.
C. Change API_KEY and SECRET_KEY that you have received in step 7 or 8 at line number 10 and 11..

9. Here, we are using twitter4j-core-3.0.3.jar for Twitter integration
10. Build your android App and install on any android device

# Design Details: Authorization With Twitter : To use Twitter API in your android application, you have to authorize the App. As a sample, I have authorized my application in TwitterApp.java file.

1. We require CONSUMER_KEY and CONSUMER_SECRET here.

2. Once your application is authorized , you can use Twitter API directly.

Handle Authorization callback: After you have authorized, you have to handle callback and save authorization details so that it doesn’t ask you for details again and again.
This is done in TwitterApp.java file.
1. Here, we get Accesstoken that shows that authorization is done.
2. Using this AccessToken, we will get our authToken , authTokenSecert and screenName. We will save these details.

Load Tweet-list: Following method is used to load the user Tweets only if the user is authorized. It takes authToken, authTokenSecert as an argument that are saved in Shared Preferences of android device. This is written in TwitterService.java file.