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

android

#1

Hi,

I’m trying to implement twitter login in my android app.
I’ve followed the instructions ( https://dev.twitter.com/twitter-kit/android/twitter-login ).

Everything is working fine if I have the twitter app installed but if I don’t when I tap on the login button I get the following exception:

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
com.twitter.sdk.android.core.TwitterApiException: method POST must have a request body.
        at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:400)
        at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
        at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
        at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
        at retrofit.Platform$Android$2$1.run(Platform.java:142)
        at java.lang.Thread.run(Thread.java:838)
06-02 11:22:23.686  24124-24124/it.quepasa E/Twitter﹕ Authorization completed with an error
com.twitter.sdk.android.core.TwitterAuthException: Failed to get request token
        at com.twitter.sdk.android.core.identity.OAuthController$1.failure(OAuthController.java:78)
        at com.twitter.sdk.android.core.internal.oauth.OAuth1aService$1.failure(OAuth1aService.java:198)
        at com.twitter.sdk.android.core.Callback.failure(Callback.java:28)
        at retrofit.CallbackRunnable$2.run(CallbackRunnable.java:53)
        at android.os.Handler.handleCallback(Handler.java:800)
        at android.os.Handler.dispatchMessage(Handler.java:100)
        at android.os.Looper.loop(Looper.java:194)
        at android.app.ActivityThread.main(ActivityThread.java:5370)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
        at dalvik.system.NativeStart.main(Native Method)

Here there is my code:

AndroidManifest.xml:

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

MainActivity.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..

LoginActivity.java:

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

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

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

#2

What version of OkHttp and Twitter Kit are you using? What Android version and device are you seeing the problem via web view login?

Also, you might try starting Fabric in debug mode so it is more clear exactly which OAuth 1 protocol step is failing as we log it:

final Fabric fabric = new Fabric.Builder(this)
                .kits(new Twitter(authConfig))
                .logger(new DefaultLogger(Log.DEBUG))
                .debuggable(true)
                .build();
Fabric.with(fabric);

#3

Thank you for your hint but I’ve managed to solve the problem just a minute ago.

I was using retrofit with okhttp 2.4 in my project and there is breaking change in it. Reverting to okttp 2.3 solved the issue.

If the developers of okhttp / retrofit stick with this you should probably change twitter kit.

Best regards

See:



#4