无法获取请求令牌方法POST必须具有请求正文

时间:2015-06-03 16:48:58

标签: java android twitter twitter-fabric

我正在尝试在我的Android应用中实现Twitter登录。 我按照说明(https://dev.twitter.com/twitter-kit/android/twitter-login)。

如果我安装了Twitter应用程序,一切正常,但如果我点击登录按钮时没有,我会得到以下例外情况。 它会打开一个webview,要求登录。

任何提示?

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)

这里有我的代码:

的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);
    }

1 个答案:

答案 0 :(得分:6)

我找到了解决方案:

这是okhttp 2.4的一个重大变化,恢复到2.3解决了我的问题。

请参阅:

https://github.com/square/okhttp/issues/751

https://github.com/square/retrofit/issues/854