Package twitter4j.auth

Examples of twitter4j.auth.RequestToken


public class CallbackServlet extends HttpServlet {
    private static final long serialVersionUID = 1657390011452788111L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Twitter twitter = (Twitter) request.getSession().getAttribute("twitter");
        RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken");
        String verifier = request.getParameter("oauth_verifier");
        try {
            twitter.getOAuthAccessToken(requestToken, verifier);
            request.getSession().removeAttribute("requestToken");
        } catch (TwitterException e) {
View Full Code Here


              }
          }
         
          try {
              twitter = new TwitterFactory().getInstance();
              RequestToken requestToken = twitter.getOAuthRequestToken()// 1
              System.out.println("Got request token.");
              System.out.println("Request token: "+ requestToken.getToken());
              System.out.println("Request token secret: "+ requestToken.getTokenSecret());
              AccessToken accessToken = null;

              BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
              while (null == accessToken) {
                  System.out.println("Open the following URL and grant access to your account:");
                  System.out.println(requestToken.getAuthorizationURL()); //2
                  System.out.print("Enter the PIN(if available) and hit enter after you granted access.[PIN]:");
                  String pin = br.readLine();
                  try{
                      if(pin.length() > 0){
                          accessToken = twitter.getOAuthAccessToken(requestToken, pin)//3
View Full Code Here

          //configura autorizacao pra minha conta de teste no twitter
          twitter.setOAuthConsumer(consumerKey, secretKey);
         
          //recebe os tokens de requisicao do twitter para posteriormente tentar o acesso
          // (forma inteligente de seguran�a, os tokens sao gerados dinamicamente pelo twitter)
          RequestToken requestToken = twitter.getOAuthRequestToken();
         
          //configuro a url que encaminhar� o usuario ao twitter (redireciono automaticamente pelo struts)
          setUrl(requestToken.getAuthorizationURL());
         
          //recebo os tokens de requisicao
          String token = (String) requestToken.getToken();
          String tokenSecret = (String) requestToken.getTokenSecret();
         
          //adiciono os tokens de requisicao a sessao pois serao usados posteriormente
          Map<String,Object> session = ActionContext.getContext().getSession();
          session.put("token",token);
          session.put("tokenSecret",tokenSecret);
View Full Code Here

   * @return auth request URI
   */
  @Override
  public String getEndUserAuthorizationRequestUri(final HttpServletRequest request) {
   
    RequestToken requestToken;
   
    try {
      // The following does not work, leads to the following error from Twitter:
      //String callbackUrl = getAbsoluteUrl(request, redirectUri);
      //logger.log(Level.INFO, "Callback URL: {0}", callbackUrl);
      //requestToken = twitter.getOAuthRequestToken(callbackUrl, "read");
      /*
      /* 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
      /* <?xml version="1.0" encoding="UTF-8"?>
      /* <hash>
        /*   <error>Desktop applications only support the oauth_callback value 'oob'</error>
        /*   <request>/oauth/request_token</request>
      /* </hash>
      /*
      /* Relevant discussions can be found on the Internet at:
      /*  http://www.google.co.jp/search?q=6c607809 or
      /*  http://www.google.co.jp/search?q=102175dd
      /*       
       */

      requestToken = twitter.getOAuthRequestToken();
      request.getSession().setAttribute("requestToken", requestToken);
     
      // Workaround for requestToken.getAuthorizationURL() ignoring configuration built with ConfigurationBuilder
      String authorizationUrl = twitter.getConfiguration().getOAuthAuthorizationURL().concat("?oauth_token=").concat(requestToken.getToken());
      logger.log(Level.INFO, "Authorization request location URI: {0}", authorizationUrl);
     
      return authorizationUrl;
     
    } catch (TwitterException ex) {
View Full Code Here

   
  @Override
  public String getAccessToken(final HttpServletRequest request) {
   
    String verifier = request.getParameter("oauth_verifier");
    RequestToken requestToken = (RequestToken) request.getSession().getAttribute("requestToken");

    AccessToken accessToken;
    try {
     
      accessToken = twitter.getOAuthAccessToken(requestToken, verifier);
View Full Code Here

        Twitter twitter = twitterFactory.getInstance();

        HttpSession session = request.getSession();

        //See if we are a callback
        RequestToken requestToken = (RequestToken) session.getAttribute(OAuthConstants.ATTRIBUTE_TWITTER_REQUEST_TOKEN);

        try {
            if (requestToken == null) {
                requestToken = twitter.getOAuthRequestToken(redirectURL);

                // Save requestToken to session, but only temporarily until oauth workflow is finished
                session.setAttribute(OAuthConstants.ATTRIBUTE_TWITTER_REQUEST_TOKEN, requestToken);

                if (log.isTraceEnabled()) {
                    log.trace("RequestToken obtained from twitter. Redirecting to Twitter for authorization");
                }

                // Redirect to twitter to perform authentication
                response.sendRedirect(requestToken.getAuthenticationURL());

                return new InteractionState<TwitterAccessTokenContext>(InteractionState.State.AUTH, null);
            } else {
                String verifier = request.getParameter(OAuthConstants.OAUTH_VERIFIER);
View Full Code Here

            Twitter twitter = new TwitterFactory().getInstance();
            twitter.setOAuthConsumer(config.getKey(), config.getSecret());

            URI uri = new URI(config.getCallbackUrl() + "?state=" + state);

            RequestToken requestToken = twitter.getOAuthRequestToken(uri.toString());
            clientSession.setNote("twitter_token", requestToken.getToken());
            clientSession.setNote("twitter_tokenSecret", requestToken.getTokenSecret());
            return AuthRequest.create(requestToken.getAuthenticationURL())
                    .build();
        } catch (Exception e) {
            throw new SocialProviderException(e);
        }
    }
View Full Code Here

            String token = callback.getQueryParam("oauth_token");
            String verifier = callback.getQueryParam("oauth_verifier");
            String twitterToken = clientSession.getNote("twitter_token");
            String twitterSecret = clientSession.getNote("twitter_tokenSecret");

            RequestToken requestToken = new RequestToken(twitterToken, twitterSecret);

            twitter.getOAuthAccessToken(requestToken, verifier);
            twitter4j.User twitterUser = twitter.verifyCredentials();

            SocialUser user = new SocialUser(Long.toString(twitterUser.getId()), twitterUser.getScreenName());
View Full Code Here

    String oAuthConsumerSecret = args[1];

    // The factory instance is re-useable and thread safe.
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthConsumer(oAuthConsumerKey, oAuthConsumerSecret);
    RequestToken requestToken = twitter.getOAuthRequestToken("oob");
    AccessToken accessToken = null;
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    while (null == accessToken) {
      System.out
          .println("Open the following URL and grant access to your account:");
      System.out.println(requestToken.getAuthorizationURL());
      System.out
          .print("Enter the PIN(if aviailable) or just hit enter.[PIN]:");
      String pin = br.readLine();
      try {
        if (pin.length() > 0) {
View Full Code Here

    try {
      String accessToken = loadToken(tokenFile, "accesstoken");
      String accessTokenSecret = loadToken(tokenFile, "accesstokensecret");

      if (StringUtils.isEmpty(accessToken) || StringUtils.isEmpty(accessTokenSecret)) {
        RequestToken requestToken = Twitter.client.getOAuthRequestToken();

        // no access token/secret specified so display the authorisation URL in the log
        logger.info("################################################################################################");
        logger.info("# Twitter-Integration: U S E R   I N T E R A C T I O N   R E Q U I R E D !!");
        logger.info("# 1. Open URL '{}'", requestToken.getAuthorizationURL());
        logger.info("# 2. Grant openHAB access to your Twitter account");
        logger.info("# 3. Create an empty file 'twitter.pin' in your openHAB home directory");
        logger.info("# 4. Add the line 'pin=<authpin>' to the twitter.pin file");
        logger.info("# 5. openHAB will automatically detect the file and complete the authentication process");
        logger.info("# NOTE: You will only have 5 mins before openHAB gives up waiting for the pin!!!");
View Full Code Here

TOP

Related Classes of twitter4j.auth.RequestToken

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.