Posting tweets from a java application

前端 未结 4 798
借酒劲吻你
借酒劲吻你 2021-02-10 07:19

I want to auto tweet from a java application. What is the simplest way to do it? Can i avoid using libraries like Twitter4j etc.,

I need an implementation for a simple a

4条回答
  •  长情又很酷
    2021-02-10 08:22

    I recommend you to use twitter4j and using this you can create oAuth requests easily. Twitter rate limits apply to desktop application and it is 150/hour. Twitter does not support basic authentication with username and password anymore.

    You are required to create an application in twitter and using the consumer key and secret only you can access your twitter account.

    If you are going to access the twitter by a desktop application then you have to select Application Type: as "Client" while creating the application. Then you can use the syntax below to update your status in twitter

     ConfigurationBuilder cb = new ConfigurationBuilder();
                cb.setDebugEnabled(true)
                    .setOAuthConsumerKey(consumerKey)
                    .setOAuthConsumerSecret(consumerSecret)
                    .setOAuthAccessToken(oAuthAccessToken)
                    .setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
                TwitterFactory tf = new TwitterFactory(cb.build());
                Twitter twitter = tf.getInstance();
                        twitter.updateStatus("This is a test message"); //ThrowsTwitterException
    

    I hope this helps you... Please let me know if this is not the answer you were looking for. Implementing your own oAuth request involve creating signature that for me was complicated and it is sensitive to time and time format that we send.

提交回复
热议问题