Results 1 to 3 of 3

Thread: problem trying to connect and post to twitter

  1. #1
    Join Date
    Mar 2011
    Posts
    2

    Default 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 "https://twitter.com/oauth/request_token" resulted in 401 (Unauthorized); invoking error handler
    Followed by:
    java.net.HttpRetryException: cannot retry due to server authentication, in streaming mode
    at sun.net.http://www.protocol.http.HttpURLConn...tion.java:1257)
    at java.net.HttpURLConnection.getResponseCode(HttpURL Connection.java:379)
    at sun.net.http://www.protocol.https.HttpsURLCo...nImpl.java:318)
    at org.springframework.http.client.SimpleClientHttpRe sponse.getStatusCode(SimpleClientHttpResponse.java :48)
    at org.springframework.web.client.DefaultResponseErro rHandler.hasError(DefaultResponseErrorHandler.java :45)
    at org.springframework.web.client.RestTemplate.doExec ute(RestTemplate.java:439)
    at org.springframework.web.client.RestTemplate.execut e(RestTemplate.java:401)
    at org.springframework.web.client.RestTemplate.exchan ge(RestTemplate.java:377)
    at org.springframework.social.oauth1.OAuth1Template.g etTokenFromProvider(OAuth1Template.java:113)
    at org.springframework.social.oauth1.OAuth1Template.f etchNewRequestToken(OAuth1Template.java:85)
    at org.springframework.social.web.connect.ConnectCont roller.connect(ConnectController.java:129)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.web.bind.annotation.support.Ha ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth odInvoker.java:176)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An notationMethodHandlerAdapter.java:436)
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho dHandlerAdapter.java:424)
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:790)
    at org.springframework.web.servlet.DispatcherServlet. doService(DispatcherServlet.java:719)
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(FrameworkServlet.java:644)
    at org.springframework.web.servlet.FrameworkServlet.d oPost(FrameworkServlet.java:560)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal(HiddenHttpMethodFilter.java:7 7)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(OncePerRequestFilter.java:76)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:235)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:102)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:298)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:859)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(Http11Protocol.java:588)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run( JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:662)
    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:
    application.url=http://localhost:8080/SocialHub/
    twitter.consumerKey=mykey
    twitter.consumerSecret=mysecret
    I put a static user name inside the application and injected it throught a AccountIdExtractor that returns a static account, such as this:
    Code:
    ...
    public class SocialHubAccountIdExtractor implements AccountIdExtractor {
    
    	@Override
    	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: http://api.twitter.com/oauth/request_token (following twitter suggestion at http://dev.twitter.com/pages/auth#request-token). 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_method="HMAC-SHA1",
    oauth_timestamp="1299163815",
    oauth_version="1.0",
    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. #2
    Join Date
    Mar 2011
    Posts
    2

    Default

    Ok.. the "Junior Member" says it all.. Perhaps other people can use the solution that worked for me.. It is posted here: http://stackoverflow.com/questions/3...ponse-code-401

  3. #3
    Join Date
    Aug 2004
    Posts
    1,068

    Default

    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.
    Craig Walls
    Spring Social Project Lead

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •