Posting tweets from a java application

前端 未结 4 799
借酒劲吻你
借酒劲吻你 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:00

    Twitter has a REST web API, and a lot of documentation. For reference:

    http://dev.twitter.com/doc

    While you don't necessarily need Twitter4J, it does make it easier. Otherwise you would need to assemble your own URL requests and take care of authentication. They offer more than one style:

    http://dev.twitter.com/pages/auth_overview

    Traditionally, OAuth is the preferred style for desktop application to web server integration--but that protocol is a bit complicated.

    There's nothing that says you can't create your Tweet() method to hide away the details of using Tweet4J or hand-rolling the request yourself.

    0 讨论(0)
  • 2021-02-10 08:04

    I want to auto tweet from a java application.

    I hope you are not spamming.. :D

    Try this one: http://code.google.com/p/java-twitter/

    You can wrap the example code into:

    public void tweet(String username, String password, String message){
    
    Api api = Api.builder().username(username).password(password).build();
    api.updateStatus(message).build().post();
    
    }
    

    And then call it as tweet.(username,pass,message)

    Looks simple to me.

    0 讨论(0)
  • 2021-02-10 08:20

    Spring Social? I saw a demo of it at SpringOne - looked pretty cool, although I personally do not have a use for it, and therefore haven't done much besides read about it. You get some OAuth capability and templates for interacting with the major social networking sites out of the box.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题