Announcement Announcement Module
No announcement yet.
problem trying to connect and post to twitter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • problem trying to connect and post to twitter

    Just downloaded the new spring social M2 release and the Samples application. I'm now I'm trying to accomplish the following:
    1 - show whether the user is connected (without the ConnectController)
    2 - if not, redirect the user to the ConnectController to get a Connection
    3 - Once the Connection was acquired, post a tweet.

    I stoped with problems in the step 2. The message I receive is:
    WARNING: POST request for "" resulted in 401 (Unauthorized); invoking error handler
    Followed by: cannot retry due to server authentication, in streaming mode
    at org.springframework.http.client.SimpleClientHttpRe sponse.getStatusCode( :48)
    at org.springframework.web.client.DefaultResponseErro rHandler.hasError( :45)
    at org.springframework.web.client.RestTemplate.doExec ute(
    at org.springframework.web.client.RestTemplate.execut e(
    at org.springframework.web.client.RestTemplate.exchan ge(
    at etTokenFromProvider(
    at etchNewRequestToken(
    at roller.connect(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(
    at org.springframework.web.servlet.DispatcherServlet. doService(
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(
    at org.springframework.web.servlet.FrameworkServlet.d oPost(
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at ternalDoFilter(
    at Filter(
    at org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal( 7)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(
    at ternalDoFilter(
    at Filter(
    at org.apache.catalina.core.StandardWrapperValve.invo ke(
    at org.apache.catalina.core.StandardContextValve.invo ke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke (
    at org.apache.catalina.core.StandardEngineValve.invok e(
    at org.apache.catalina.connector.CoyoteAdapter.servic e(
    at org.apache.coyote.http11.Http11Processor.process(H
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(
    To be able to run this environment I registered an application inside twitter.. that registration gave me a consumer key and consumer secret. I stored them and put inside my properties file, together with my sample application url. Following is my properties file:
    I put a static user name inside the application and injected it throught a AccountIdExtractor that returns a static account, such as this:
    public class SocialHubAccountIdExtractor implements AccountIdExtractor {
    	public Serializable extractAccountId(WebRequest arg0) {
    		return "myuser";
    I'm sure the consumerKey, consumerSecret and the user mentioned above are correct. I tryied changing the request token url to this one without success: (following twitter suggestion at I received the same error message.

    I investigated the posted header parameters and found this one:
    {Authorization=[OAuth oauth_callback="http%3A%2F%2Flocalhost%3A8080%2Fco nnect%2Ftwitter",
    oauth_consumer_key="a messed key",
    oauth_nonce="a messed nonce",
    oauth_signature="a messed signature"]}
    I'm lost in what could be the cause.. please, any directions would be appreciated. Please let me know if it is necessary to show you any other information.

  • #2
    Ok.. the "Junior Member" says it all.. Perhaps other people can use the solution that worked for me.. It is posted here:


    • #3
      You're correct in setting up your application as a "Browser" application in Twitter and providing a callback URL. The "Client" setting is more appropriate for desktop applications that interact with Twitter.

      That said, the callback URL you set will be ignored if you pass along a different callback URL when asking for a request token. You must set it to something or else Twitter will reset your application type to be a "Client" application. But the actual URL is unimportant when using Spring Social to handle connections because the service provider "connect" framework will always send a callback URL in the request token call.

      As a matter of good practice, you should probably set it to the real callback URL handled by your application. One caveat is that Twitter doesn't seem to like it if you give it a http://localhost:8080-based URL, so you'll need to set it to some real-world-like URL even if you're only testing your application locally.