[Android Software Development] Geeks Empire:
Twitter Account [Authentication]

​

Authentication by Twitter has Complex aspect.

First you should Create Twitter Account, Then Create Web App through www.twitter.com (to get Public & Secret Key), Enable Twitter on Firebase (Not Required But I recommend it) & Install 3rd-Party Plugin on Android Studio (Fabric API).

Go to https://twitter.com/ & Sign Up then go to https://apps.twitter.com/ & Create App.

Name the App & Write Description & WebSite.

In App Page > Keys & Access Token

. Consumer Key (API Key) = XXXXX

. Consumer Secret (API Secret) = XXXXX

Save these value to resources of your app. res > values > string

</resources>
<string name="twitter_consumer_key">[B]API Key[/B]</string>
<string name="twitter_consumer_secret">[B]API Secret[/B]</string>
</resources>

- Go to Login & Auth on Firebase Select Twitter & Paste API Key + API Secret.

On Android Studio navigate to File > Setting > Plugin& Search for Fabric (Click Browse)

After Plugin Downloaded It will ask for Restart to Complete Installation.

Then Fabric Plugin icon will appear on toolbar & maybe Right-Panel.
​

​

Click on Plugin & Sign Up. Then you will see your current project on Fabric list. Select it & click Next.

From List of All Kits select Twitter & click Install. It will ask for API Key + API Secret

Fabric will Apply All Modification it needs to your project & after that you project will be ready for Twitter Auth.

But for Developer It is always important points to understand every part of tools and apps.

* Fabric Inside build.grade (Module: App)

before Android Plugin

apply plugin: 'com.android.application'

Add this Script

buildscript {
repositories {
maven { url 'https://maven.fabric.io/public' }
}
dependencies {
classpath 'io.fabric.tools:gradle:1.+'
}
}

after Android Plugin set up fabric plugin

apply plugin: 'io.fabric'

after android{} functions add Fabric Repositories

repositories {
mavenCentral()
maven { url 'https://maven.fabric.io/public' }
}

& Inside dependencies{} add

compile('com.twitter.sdk.android:twitter:1.13.1@aar') {
transitive = true;
}

* Fabric Inside Manifest

in <application/> add

<meta-data
android:name="io.fabric.ApiKey"
android:value="API_KEY" />

* Fabric Inside MainActivity Class

before setContentView(VIEW) under onCreate(Bundle)

TwitterAuthConfig authConfig = new TwitterAuthConfig([COLOR=Red]API_KEY[/COLOR], [COLOR=Red]API_SECRET[/COLOR]);
Fabric.with(this, new Twitter(authConfig));

Fabric Also provides Button design for Twitter with custom features to handle Auth CallBack.

<com.twitter.sdk.android.core.identity.TwitterLoginButton/>

You define it in layout.xml & then Declare it like normal views on activity.

But performing action is different.

/*TWITTER Sign-In*/
twitterButton.setCallback(new Callback<TwitterSession>() {
@Override
public void success(Result<TwitterSession> result) {
Toast.makeText(getApplicationContext(), [COLOR=Red][B]result[/B][/COLOR].data.getUserName(), Toast.LENGTH_LONG).show();
}
@Override
public void failure(TwitterException exception) {}
});

without any extra Intent it will redirect you to Twitter Auth Page.

Also By using this button you can handle CallBack Result.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
twitterButton.onActivityResult(requestCode, resultCode, [COLOR=Red][B]data[/B][/COLOR]);
}

Also I used Fabric for Twitter Auth cause I can retrieve more Info than Firebase.Auth("twitter").

Fabric Plugin Developed by Twitter Developers So It really works smoothly & really best way to Auth with Twitter Account.

Thanks for Supporting GeeksEmpire projects

​

Don't Forget To Hit Thanks
​