Package twitter4j.auth

Examples of twitter4j.auth.AccessToken


     */
    public AccessToken oAuthOnCallBack(String oauth_verifierParameter) throws TwitterException {
        if (tmpRequestToken == null)
            throw new IllegalStateException("RequestToken is empty. Call oAuthLogin before!");

        AccessToken aToken = twitter.getOAuthAccessToken(tmpRequestToken, oauth_verifierParameter);
        twitter.verifyCredentials();
        tmpRequestToken = null;
        return aToken;
    }
View Full Code Here


        ElasticUserSearch uSearch = newMockUserSearch(user);
        MySession session = (MySession) tester.getWicketSession();
        session.setTwitterSearch(ts);
        session.setFormData("tmp@tmp.de", "test");
        // token starts with user id!
        Cookie cookie = session.afterLogin(new AccessToken("123-normalToken", "tSec"), uSearch, resp);
        verify(uSearch).save(user, false);
        assertEquals(TwitterSearch.COOKIE, cookie.getName());
        assertEquals("123-normalToken", cookie.getValue());

        uSearch = newMockUserSearch(user);
View Full Code Here

        JUser user = new JUser("testuser");
        ElasticUserSearch uSearch = newMockUserSearch(user);
        MySession session = (MySession) tester.getWicketSession();
        session.setTwitterSearch(ts);
        try {
            session.afterLogin(new AccessToken("123-normalToken", "tSec"), uSearch, resp);
            assertTrue(false);
        } catch (IllegalArgumentException ex) {
            assertTrue(true);
        }
    }
View Full Code Here

              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
                      }else{
                          accessToken = twitter.getOAuthAccessToken(requestToken); //3
                      }
                  } catch (TwitterException te) {
                      if(401 == te.getStatusCode()){
                          System.out.println("Unable to get the access token.");
                      }else{
                          te.printStackTrace();
                      }
                  }
              }
              System.out.println("Got access token.");
              System.out.println("Access token: " + accessToken.getToken());
              System.out.println("Access token secret: " + accessToken.getTokenSecret());

              try {
                  prop.setProperty("oauth.accessToken", accessToken.getToken());
                  prop.setProperty("oauth.accessTokenSecret", accessToken.getTokenSecret());
                  os = new FileOutputStream(file);
                  prop.store(os, "twitter4j.properties");
                  os.close();
              } catch (IOException ioe) {
                  ioe.printStackTrace();
View Full Code Here

          //recuperando os tokens da sessao
          String token = (String) ActionContext.getContext().getSession().get("token");
          String tokenSecret = (String) ActionContext.getContext().getSession().get("tokenSecret");
          try{
            //tenta conseguir um accessToken atrav�s dos requestTokens para tentar liberar o acesso ao twitter
            AccessToken accessToken = twitter.getOAuthAccessToken(token, tokenSecret);
           
            //salva o accessToken na sessao pra nao precisar autenticar cada vez que for postar um tweet
            //Para isto, deveria ser feita uma verifica��o mas creio que foge do intuito deste programa
            Map<String,Object> session = ActionContext.getContext().getSession();
            session.put("aToken",accessToken.getToken());
            session.put("aTokenSecret",accessToken.getTokenSecret());
           
            //supostamente esta linha conseguiria a autorizacao pra acessar o twitter
            //mas por algum motivo que eu nao sei qual �, o twitter nao autoriza minha aplica��o e retorna ERRO1
            twitter.setOAuthAccessToken(accessToken);
          }catch(TwitterException ex){
View Full Code Here

  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);
   
      return accessToken.toString();
     
    } catch (TwitterException ex) {
     
      logger.log(Level.SEVERE, null, ex);
     
View Full Code Here

                if (request.getParameter(OAuthConstants.OAUTH_DENIED) != null) {
                    throw new OAuthException(OAuthExceptionCode.USER_DENIED_SCOPE, "User denied scope on Twitter authorization page");
                }

                // Obtain accessToken from twitter
                AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);

                if (log.isTraceEnabled()) {
                    log.trace("Twitter accessToken: " + accessToken);
                }

                // Remove requestToken from session. We don't need it anymore
                session.removeAttribute(OAuthConstants.ATTRIBUTE_TWITTER_REQUEST_TOKEN);
                TwitterAccessTokenContext accessTokenContext = new TwitterAccessTokenContext(accessToken.getToken(), accessToken.getTokenSecret());

                return new InteractionState<TwitterAccessTokenContext>(InteractionState.State.FINISH, accessTokenContext);
            }
        } catch (TwitterException twitterException) {
            throw new OAuthException(OAuthExceptionCode.TWITTER_ERROR, twitterException);
View Full Code Here

    private AccessToken getAccessToken(
            final Twitter twitter,
            final String token,
            final String tokenSecret) throws TwitterException {

            final AccessToken accessToken =  twitter.getOAuthAccessToken(token, tokenSecret);
            log.info(String.format("Auth Token {%s Token Secret {%s ", accessToken.getToken(), accessToken.getTokenSecret()));
            twitter.setOAuthAccessToken(accessToken);
            if (accessToken != null) {
                    log.info(String.format("Got access token for user %s", accessToken.getScreenName()));
            }
            return accessToken;
    }
View Full Code Here

        }, 5, TimeUnit.SECONDS);

        // Generate a tweet on your timeline
        // We need to read settings from elasticsearch.yml file
        Settings settings = internalCluster().getInstance(Settings.class);
        AccessToken accessToken = new AccessToken(
                settings.get("river.twitter.oauth.access_token"),
                settings.get("river.twitter.oauth.access_token_secret"));


        Twitter twitter = new TwitterFactory().getInstance();
View Full Code Here

    // 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());
View Full Code Here

TOP

Related Classes of twitter4j.auth.AccessToken

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.