Announcement Announcement Module
Collapse
No announcement yet.
twitter template getting the user's email Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • twitter template getting the user's email

    Hi I have successfully connected with the twitter template and retrieve the user's info but I really dont know how to get the user's email. is this posible?? and if it is how can i do it?

    Thanks !!

  • #2
    It's not possible because Twitter does not expose their users' emails through their API.

    Comment


    • #3
      I am not getting user data

      HI,

      org.scribe.model.Token requestToken =(org.scribe.model.Token) request.getAttribute("twitter_request_token", WebRequest.SCOPE_SESSION);
      String accessToken= twitterProvider.getOAuthService().getRequestToken( ).getSecret();

      after getting accessToken how to get user details ,
      I am using spring-social twitter



      Please help me

      Thank'you

      Comment


      • #4
        First, you should have really started a new thread, as this is only slightly related to the original topic of this thread. :-)

        That said, the request token secret is not the same thing as the access token. Twitter uses OAuth 1.0a. Therefore, once you get the request token, you must redirect the user's browser to Twitter's authorization page to authorize the request token. After they do that, then they'll be redirected back to your app and the redirect URL will have a verifier code as a query parameter. You must then trade the (now verified) request token along with the verifier code for the access token.

        I see you're using Scribe and Scribe can handle much of that for you. I believe you'll still be responsible for handling the redirect, because (correct me if I'm wrong), Scribe will only handle the fetching of the request token and the exchange of that token and verifier for the access token.

        However, you're also using Spring Social and Spring Social's ConnectController can handle *all* of that for you, including the redirect to Twitter and the handling of the redirect back from Twitter. In fact, using ConnectController, the only OAuth detail you'll have to deal with directly is your Twitter consumer key and secret. I recommend that you have a look at http://static.springsource.org/sprin...onnecting.html for the details on using ConnectController.

        Oh, and for what it's worth, if you really want to deal with the lower-level OAuth stuff, Spring Social can help you there, too. OAuth1Template is the lowest-level OAuth 1 support class and just a step up from that you might find TwitterConnectionFactory or TwitterServiceProvider to be interesting. (But truly, ConnectController is the smoothest way to go.)

        Comment


        • #5
          twitter authontication

          Thanks for replaying,

          But i try a lot, i cont understand what i do on next

          this is my steps

          1.<a href="/xxxx/users/twitter">Connect to Twitter</a>

          2.@RequestMapping("/twitter")
          public String getsocialurl(Model uiModel,HttpServletRequest request,WebRequest request1) {
          org.scribe.model.Token requestToken = twitterProvider.getOAuthService().getRequestToken( );
          request1.setAttribute("twitter_request_token", requestToken, WebRequest.SCOPE_SESSION);
          return "redirect:" + twitterProvider.getAuthorizeUrl() + "?oauth_token=" + (requestToken).getToken();
          }
          3. after login and clicking addapp, coming in to this page(callback to this page)

          @RequestMapping(value = "/userdata", method = RequestMethod.GET, params = "oauth_token")
          public String authorizeTwitterCallback(@RequestParam(value = "oauth_verifier", defaultValue = "verifier") String verifier,
          WebRequest request) {
          request.getAttribute("twitter_request_token", WebRequest.SCOPE_SESSION);
          org.scribe.model.Token requestToken = twitterProvider.getOAuthService().getRequestToken( );

          String accessToken= twitterProvider.getOAuthService().getRequestToken( ).getSecret();

          if (accessToken == null) {
          return "connect/twitterConnect";
          }

          if (accessToken != null) {
          in this if condition what will i do
          please help me.....,

          }
          }

          Thank'you
          praveen

          Comment


          • #6
            Again, the request token's secret is not the same thing as the access token. You must exchange the request token and the verifier for the access token. The OAuth 1 steps are as follows:

            1. Fetch a request token and secret from the provider
            2. Redirect the user to the provider to authorize the request token
            3. Upon redirect back, exchange the request token for the access token (which is a completely different token and secret from what you get in step 1)

            If you were using Spring Social's OAuth1Template, you would call its exchangeForAccessToken() method passing in an AuthorizedRequestToken (which carries both the request token and the verifier) and get back an OAuthToken, which would be the access token and access token secret. Or better yet, if you were using Spring Social's ConnectController, it would do all of that for you.

            Since you're using Scribe, however, I'll refer you to Scribe's documentation for details on how to exchange the request token and verifier for an access token.

            No matter how you get the access token (whether you're using Scribe or Spring Social) you can then use that access token to construct an instance of TwitterTemplate. From TwitterTemplate, you can then do:

            Code:
            TwitterProfile profile = twitterTemplate.userOperations().getUserProfile();
            I encourage you to have a look at Spring Social Showcase (https://github.com/SpringSource/spri...ocial-showcase) which shows how to use ConnectController to handle the connection process and also how to use TwitterTemplate to fetch the user profile.

            Comment


            • #7
              Hi habuma,

              Thank for replay...,

              After call back function i wrote this

              Token requestToken = twitterProvider.getOAuthService().getRequestToken( );
              String accessToken= twitterProvider.getOAuthService().getRequestToken( ).getToken();
              String secret= twitterProvider.getOAuthService().getRequestToken( ).getSecret();

              if (accessToken == null) {
              return "connect/twitterConnect";
              }
              if (accessToken != null) {
              org.springframework.social.twitter.TwitterTemplate twitter = new org.springframework.social.twitter.TwitterTemplate (consumerkey, consumerSecret,accessToken,secret);
              twitter.getProfileId()


              then i got this error how to resolve it please tell me.

              DEBUG org.springframework.web.client.RestTemplate - Created GET request for "https://api.twitter.com/1/account/verify_credentials.json"
              2012-01-09 18:23:43,846 [tomcat-http--6] DEBUG org.springframework.web.client.RestTemplate - Setting request Accept header to [application/json]
              2012-01-09 18:24:03,499 [tomcat-http--6] DEBUG org.springframework.web.servlet.DispatcherServlet - Could not complete request
              org.springframework.web.util.NestedServletExceptio n: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/security/AuthenticationException
              at org.springframework.web.servlet.DispatcherServlet. doDispatch(DispatcherServlet.java:839)


              Thank you...,
              praveen

              Comment


              • #8
                I do not know how to make this more clear that this: The request token you are fetching is *NOT* the access token. In OAuth 1, there are 2 different tokens in play. The request token can only be used to get an access token and cannot be used as the access token. So, when you say this:

                Code:
                Token requestToken = twitterProvider.getOAuthService().getRequestToken( );
                String accessToken= twitterProvider.getOAuthService().getRequestToken( ).getToken();
                The thing you are calling "accessToken" is not an access token at all; it is actually the request token and you cannot use it for anything other than getting an access token--which is a separate step. You cannot use it when constructing TwitterTemplate.

                Nowhere in the code you show do you ever actually get an access token. After the callback, you'll need to exchange the request token and the verifier received in the callback for the actual request token. With Scribe you do that by calling getAccessToken() on the OAuth service, passing in the request token and the verifier.

                Again, since you are using Scribe, you should read Scribe's documentation and see their examples to know how to properly use the OAuth service. I can't help you much with that more than I already have.

                That said, if you aren't tied to using Scribe, you can using Spring Social's connection support and a lot of the complexity in the OAuth "dance" goes away and I'll be more capable and happy to help you with that.

                Comment


                • #9
                  Hi,

                  Thank for replay,

                  i resolved it.

                  TwitterConnectionFactory connectionFactory =
                  new TwitterConnectionFactory(" ", " ");
                  OAuth1Operations oauthOperations = connectionFactory.getOAuthOperations();
                  OAuthToken requestToken = oauthOperations.fetchRequestToken("http://192.168.1.206:8080/SocialTV/users1/userdata1", null);

                  String authorizeUrl = oauthOperations.buildAuthorizeUrl(requestToken.get Value(), OAuth1Parameters.NONE);
                  req.getSession().setAttribute("requestToken", requestToken);
                  response.sendRedirect(authorizeUrl);


                  after that twitter login page is not comming on pop up,
                  how will it come....

                  Please Help me.

                  Praveen

                  Comment


                  • #10
                    First, I really recommend that you take a look at the Spring Social samples (https://github.com/SpringSource/spring-social-samples), especially the showcase sample, as it demonstrates how to do everything you're trying to do, except that instead of doing it directly, the samples use ConnectController. ConnectController really does make this whole process easier and you should consider using it, especially if your app is based on Spring MVC.

                    That said...I'm assuming that the values you gave to TwitterConnectionFactory's constructor were removed for privacy reasons and that you're not actually creating that object with empty strings.

                    What is the context of this code? Is it in a servlet? In a Spring MVC controller's handler method? Somewhere else? May I assume that the response object is an instance of HttpServletResponse? You say that the Twitter login page is not coming on pop up--but what actually does happen?

                    Comment


                    • #11
                      how to get twitter Authorized userdata

                      Hi,Habuma

                      Thanks for raplay,

                      TwitterConnectionFactory's plase what i will do, and once authenticate that user comming on next time, i am not asking login with twitter directly showing the twitter details and post the comment into twitter profile how it will do. please help me.


                      Thank'you
                      praveen

                      Comment


                      • #12
                        Hi,Habuma

                        Thanks for raplay,

                        TwitterConnectionFactory's plase what i will do, and once authenticate that user comming on next time, i am not asking login with twitter directly showing the twitter details and post the comment into twitter profile how it will do. please help me.


                        Thank'you
                        praveen

                        Comment

                        Working...
                        X