How does Twitter OAuth work in Android?

I have been searching for an answer for quite some time, and I have admit that I am pretty stuck. I am attempting to implement Twitter in my application and have found it somewhat challenging. It seems the way to do it is to register my app with Twitter(I have already done so) as a Browser application. I don’t know what to use for my callback url though. I really want to just return to my current activity in the application, and not be redirected to a callback url. What should I put for that? I am pretty stuck…

  • Android Dash/doted line issue?
  • EditText background base line color changing based on its focus in android
  • Remove shadow from top and bottom of ListView in android?
  • touchend event doesn't work on Android
  • Set a time-out for android requestSingleUpdate
  • Could not find Library.apk!
  • Related posts:

    Can you hide an element in a layout, such as a spinner, depending on an activity?
    Lollipop EditBox styling
    how to make a relative layout scrollable when it has many children views?
    Proguard returned with error code 1. See console
    Multicast on Android 2.2
    Difference between FlurryAgent.logEvent and FlurryAgent.onEvent
  • How do Google's G Suite Apps share data?
  • android drawable from file path
  • Dynamically change the limit of a Firebase Query Reference on Android
  • Android (distributed application) primary key strategy
  • getting Error: spawn EACCES while ionic build android in ubuntu 14.04
  • How can I scale textviews using shared element transitions?
  • One Solution collect form web for “How does Twitter OAuth work in Android?”

    This is how it works… you do the call to twitter authentication URL (by opening a web browser). The URL of the authentication must contain the callback URL. A callback URL usually looks like this: x-your-application-name-oauth-twitter://callback (*).

    Second step is to add an intent filter to your Activity (implementing twitter auth requires you to know how Android works (unless you find a tutorial that does everything for you, but I think that’s not the case seems you seem to be a smart guy, aren’t you?)). Whatever, you do so by adding something like this in your manifest:

        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="x-your-application-name-oauth-twitter" android:host="callback"/>

    This is basically a way to say to Android OS: “hey dude, I can handle any URL that looks like x-your-application-name-oauth-twitter://callback“. That way, once user has authenticated, twitter will call that URL and your application will reclaim the control.

    Usually, your activity must be created with the android:launchMode="singleTask" tag, then you must override the onNewIntent method of your activity that will be called once your application has the control again. Inside the Intent you will find information about the callback.

    (*) Building the URL that you must launch (and that will allow users to authenticate) is somehow difficult. OAuth is a good but kind of hard to learn standard. So, you can use third-party libraries that will help you on this. You could, for instance, use Oauth Signpost java library. However, I would recommend you to stick to twitter4j library that will help you with OAuth and also allows you to interact with Twitter API.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.