skip to Main Content

I did the following code to post a message on Twitter using Twitter4j on Java:

public static void main(String[] args) throws TwitterException {
String consumerKey = ".....";
String consumerSecret = "....";
String accessToken = "....";
String accessTokenSecret = "....";

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
        .setOAuthConsumerKey(consumerKey)
        .setOAuthConsumerSecret(consumerSecret)
        .setOAuthAccessToken(accessToken)
        .setOAuthAccessTokenSecret(accessTokenSecret);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();

//Posting a Tweet
twitter.updateStatus("Hello , This is a sample tweet");

}

But, I get the following error:

Exception in thread "main" 403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following). 
message - SSL is required
code - 92

Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=0f7b8a6a
TwitterException{exceptionCode=[b2b52c28-0f7b8a6a], statusCode=403, message=SSL is required, code=92, retryAfter=-1, rateLimitStatus=null, version=3.0.0}

I get the same error whether I try to get a timeline or to make a query or to send a post.

I think I could not have hit any limit, because this is the first try I’m doing from Java.
Does someone have an idea about the reason ?

2

Answers


  1. Chosen as BEST ANSWER

    The issue is solved by adding:

    cb.setUseSSL(true);
    

    I don't know exactly the explanation behind. Could someone explain ?


  2. You must be using an older version of Twitter4J.

    For older version of Twitter4j you have to enable .setUseSSL(true);

    In previous versions (before 4.x – Mar, 2014), you had to select if you were going to connect to Twitter’s API via an SSL or a standard request, but twitter has since turned off the ability to connect via a non-SSL connection.

    In version 4.xx of twitter4j that setUseSSL(..) method has been removed and the library will use SSL by default.

    Twitter changed its API to require SSL for user privacy reasons

    Communicating over TLS preserves user privacy by protecting
    information between the user and the Twitter API as it travels across
    the public Internet.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search