Java – Unable to get request token method POST must have a request body

Unable to get request token method POST must have a request body… here is a solution to the problem.

Unable to get request token method POST must have a request body

I’m trying to implement Twitter login in my Android app.
I have followed the instructions ( ) to operate.

If I install the Twitter app, everything works fine, but if I don’t, when I hit the login button, I get the exception below.
It should open a WebView that asks for login.

Any tips?

06-02 11:22:23.531  24124-24124/it.quepasa W/dalvikvm: VFY: unable to resolve virtual method 39779: Lretrofit/client/OkClient;.openConnection (Lretrofit/client/Request ;)Ljava/net/HttpURLConnection;
06-02 11:22:23.611  24124-24124/it.quepasa E/Twitter﹕ Failed to get request token method POST must have a request body.
        at retrofit. RestAdapter$RestHandler.invokeRequest(
        at retrofit. RestAdapter$RestHandler.access$100(
        at retrofit. RestAdapter$RestHandler$2.obtainResponse(
        at retrofit.
        at java.util.concurrent.ThreadPoolExecutor.runWorker(
        at java.util.concurrent.ThreadPoolExecutor$
        at retrofit. Platform$Android$2$
06-02 11:22:23.686  24124-24124/it.quepasa E/Twitter﹕ Authorization completed with an error Failed to get request token
        at retrofit. CallbackRunnable$
        at android.os.Handler.handleCallback(
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(
        at dalvik.system.NativeStart.main(Native Method)

Here is my code :


        android:value="XXXXXXXX" />

Main Activity .java:

    TwitterAuthConfig authConfig = new TwitterAuthConfig(TWITTER_KEY, TWITTER_SECRET);
    Fabric.with(this, new Twitter(authConfig), new Crashlytics()); I've tried without crashlytics, same problem. Crashlytics works..

Log in to Activity .java:

    loginButton = (TwitterLoginButton) findViewById(;
    loginButton.setCallback(new Callback<TwitterSession>() {
        public void success(Result<TwitterSession> result) {
            Log.d(TAG, "Success");

        public void failure(TwitterException exception) {
            Log.d(TAG, "Failure");

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        loginButton.onActivityResult(requestCode, resultCode, data);


I found a solution :

This is a breaking change in okhttp 2.4, reverting to 2.3 solved my problem.

See also:

Related Problems and Solutions