android twitter retrieveRequestToken 401 on request token

对着背影说爱祢 提交于 2019-11-29 03:44:21

I have spent several hours on this. Seems that you have to set ANY value to the callback url in the Settings tab in your Twitter application developer panel. Keeping the default empty value disables dynamic callback urls.

All the tutorials and all the information I have found online is just void. Twitter long removed the "Client / Website" radio button.

Moreover, OAuth checks for clock skews.

I just had the same problem. It only appeared on my dev phone, but on the emulator and another phone the code worked fine. After trying out several solutions to related questions with no luck, eventually it turned out that I had not set the time and date on the dev phone, which doesn't have a sim-card in it. This caused SSL certificates to be invalid and OAuth request to fail, as well as anything else that used HTTPS. After setting the time the problems went away.

**1) **Set date and time to the right values, this will help to fix this issue.****

2)

private OAuthConsumer consumer;
private OAuthProvider provider;
...
...
...
provider = new CommonsHttpOAuthProvider (
                TWITTER_REQUEST_TOKEN_URL, 
                TWITTER_ACCESS_TOKEN_URL,
                TWITTER_AUTHORIZE_URL);

private void askOAuth() {
        try {
            consumer = new CommonsHttpOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
            provider = new CommonsHttpOAuthProvider("http://twitter.com/oauth/request_token",
                                                "http://twitter.com/oauth/access_token",
                                                "http://twitter.com/oauth/authorize");

            provider.setOAuth10a(true);

            String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
            Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show();
            this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(authUrl)));
        } catch (Exception e) {
            Log.e(APP, e.getMessage());
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
        }
    }

3) is your twitter app configured as Browser? try with this keys:

Consumer key

sdOjEI2cOxzTLHMCCMmuQ

Consumer secret

biI3oxIBX2QMzUIVaW1wVAXygbynuS80pqSliSDTc

using https in place of http in provider

d-man

finally done, check out the following post

android twitter outh tutorial callback problem

yes totramon is right...If you are facing problem only while authentication problem , you may have to set device time. I was facing the same problem and solved with this solution only. Also if you are using old twitter api , you need to change it to stable version api(2.1.4). You can find from the following link :

http://twitter4j.org/en/index.html

Enjoy..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!