“SSL is required” exception while requesting OAuthRequest Token using Twitter4J library

ぐ巨炮叔叔 提交于 2019-12-10 17:45:37

问题


I was trying this sample application provided here, I am getting "SSL is required" exception in this particular piece of code

private void askOAuth() {
        ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
        configurationBuilder.setOAuthConsumerKey(Const.CONSUMER_KEY);
        configurationBuilder.setOAuthConsumerSecret(Const.CONSUMER_SECRET);
        Configuration configuration = configurationBuilder.build();
        twitter = new TwitterFactory(configuration).getInstance();

        try {
            requestToken = twitter.getOAuthRequestToken(Const.CALLBACK_URL);
            Toast.makeText(this, "Please authorize this app!", Toast.LENGTH_LONG).show();
            this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
        } catch (TwitterException e) {
            Log.e(TAG, e.getMessage());
        }
    }

when twitter.getOAuthRequestToken(Const.CALLBACK_URL); is executed I get this exception.

I have configure consumer key, consumer secret and callback url to that of my application.


回答1:


Got this solved If you are using twitter4j version 3 or less that in ConfigurationBuilder you have to set

configurationBuilder.setUseSSL(true);

because twitter has made ssl as mandatory to make API request

for twitter4j version 4, by default ssl is used.



来源:https://stackoverflow.com/questions/22742478/ssl-is-required-exception-while-requesting-oauthrequest-token-using-twitter4j

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