问题
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