Announcement Announcement Module
No announcement yet.
Getting Twitter Authentication error. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting Twitter Authentication error.

    So I just wrote some code to use JMS Queue to send a String message which is then used to back a Spring Integration channel, which is being listened on my an <int-twitter:outbound-channel-adapter> which references my TwitterTemplate bean and therefore sending the JMS Message should cause a status update to my account.

    However, I am getting an error.
    First a warning
    "2012-03-17 18:55:29,575 [http-bio-8080-exec-1] WARN org.springframework.web.client.RestTemplate - POST request for "" resulted in 401 (Unauthorized); invoking error handler"

    Then the error, the stack trace has more, but nothing worth noting.

    SEVERE: Servlet.service() for servlet [eventgate] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.client.ResourceAccessException: I/O error: cannot retry due to server authentication, in streaming mode; nested exception is cannot retry due to server authentication, in streaming mode] with root cause cannot retry due to server authentication, in streaming mode
    	at org.springframework.http.client.SimpleClientHttpResponse.getStatusCode(
    	at org.springframework.web.client.DefaultResponseErrorHandler.hasError(
    	at org.springframework.web.client.RestTemplate.doExecute(
    	at org.springframework.web.client.RestTemplate.execute(
    	at org.springframework.web.client.RestTemplate.postForObject(
    	at com.perfectworldprogramming.eventgate.utils.TwitterService.sendTweet(
    Here is my code and configuration

    <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
            <property name="brokerURL" value="vm://embedded?broker.persistent=false"/>
        <bean id="twitterQueue" class="org.apache.activemq.command.ActiveMQQueue">
            <constructor-arg value="queue.twitter"/>
        <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
            <property name="connectionFactory" ref="connectionFactory"/>
            <property name="defaultDestination" ref="twitterQueue"/>
    <bean id="twitterTemplate" class="">
        	<constructor-arg value="${twitter.oauth.consumerKey}"/>
        	<constructor-arg value="${twitter.oauth.consumerSecret}"/>
        	<constructor-arg value="${twitter.oauth.accessToken}"/>
        	<constructor-arg value="${twitter.oauth.accessTokenSecret}"/>
        <int-jms:channel id="twitterChannel" queue-name="queue.twitter"/>

        @Transactional(propagation = Propagation.REQUIRES_NEW)
        public void sendTweet(TwitterMessage messageType, String... args) {
            String message = messages.get(messageType);
            message = MessageFormat.format(message, args) + Calendar.getInstance().toString();
            if (message.length() > tweetSize) {
                message = message.substring(0, 139);
            boolean testing = twitterTemplate.isAuthorized();
            if (testing) {
    It looks correct to me, and in my .properties file with my Twitter credentials all seems fine, I even get true returned for twitterTemplate.isAuthorized();

    Any help would be appreciated.



  • #2
    Well judging by the stack trace, you clearly have an issue with you credentials. I would suggest to try to post a status directly using SpringSocial to verify.
    However since you are already using SpringIntegration you might as well use our Twitter module especially for the use case as simple as yours. Here are some samples


    • #3
      Ohh wait, i'll take that back.I see you are using SI for this. Sorry about it.

      Did it ever work for you? If so there could be two issues - both related to Twitter itself. 1. You might be a subject of rate limiting (posting too many messages in the certain timeframe); 2. You can't post status with the same content more than once.

      Can you confirm?


      • #4
        Thanks Oleg. Confirmed. I changed the message to have a timestamp so it would be different each time. I only tried about 10 times total till I gave up and posted.

        I have an idea, I am using a Mac with Safari and I always have privacy browsing turned on. Let me turn that off and try to send one.




        • #5
          Nope, not privacy browsing. I am looking at

          In which Craig has some interesting points.

          and the link by the other guy in that thread

          About to try them out. I have a good feeling about the changing it from client to browser, since the call starts from a URL link on my website.

          Thanks again Oleg


          p.s. I think we should just ignore that "article" BB posted about JBoss 7. It is obvious from the text that he doesn't know anything about what Spring has and is just thinking Spring is just a container/DI and nothing more. At this point it is like he is being a troll.


          • #6
            Still, no luck.

            However, I think Twitter is having issues with their site. It keeps popping up a message about being "over capacity"

            Anyway, thanks for your help. I need to go onto other stuff for the next week, so I will have to come back to this much later.



            • #7
              Yep, it was a twitter problem. Couldn't get it to change my oauth token keys from read to read/write. I kept clicking the read/write radio button and got that over capacity error. What I finally did to get it to work was after clicking the read/write radio button then submitting and getting the capacity error message, I then clicked on the regenerate keys button for the tokens, and when I did that I got the new keys and it then also showed as read/write on the web site.

              Copied the new keys to my properties file and now I am tweeting like crazy through my app.

              Thanks Oleg for all your help, you are always there to hellp us all out. Next Spring One I'm buying you a beer.


              • #8
                i haved the same problem,i solved making an account here:
                (in "access token" put the: Access level = Read and write)

                them just follow the API:
                and made an example step by step.



                • #9
                  Please refer my blog where I posted an example for Twitter Integration - Post a Tweet, Receive a Tweet

                  The first example deals with the steps you would need to authenticate and authorize your application with twitter.

                  Hope that helps!