Package twitter4j.auth

Examples of twitter4j.auth.AccessToken


    LOGGER.info("Access Token:        '" + accessToken + "'");
    LOGGER.info("Access Token Secret: '" + accessTokenSecret + "'");

    twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    twitterStream.setOAuthAccessToken(new AccessToken(accessToken,
                                                      accessTokenSecret));
    twitterStream.addListener(this);
    avroSchema = createAvroSchema();
    dataFileWriter = new DataFileWriter<GenericRecord>(
        new GenericDatumWriter<GenericRecord>(avroSchema));
View Full Code Here


    }

    public UserTwitterLink createTwitterLinkageFromLoginInformation(TwitterLoginInformation information, String verifier) throws TwitterException {
        Twitter twitter = information.getTwitter();
        RequestToken requestToken = information.getRequestToken();
        AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, verifier);

        twitter4j.User twitterUser = twitter.showUser(twitter.getId());
        return new UserTwitterLink(
                null, twitter.getId(), null, twitter.getScreenName(), twitterUser.getName(), accessToken.getToken(), accessToken.getTokenSecret(),
                twitter.showUser(twitter.getId()).getProfileImageURL().toString());
    }
View Full Code Here

                twitter.showUser(twitter.getId()).getProfileImageURL().toString());
    }

    @Override
    public void sendDirectMesage(String token, String tokenSecret, long twitterId, String message) throws TwitterException {
        AccessToken accessToken = new AccessToken(token, tokenSecret);
        Twitter twitter = new TwitterFactory(conf).getInstance(accessToken);
        twitter.sendDirectMessage(twitterId, message);
    }
View Full Code Here

        twitter.sendDirectMessage(twitterId, message);
    }

    @Override
    public void updateStatus(String token, String tokenSecret, String message) throws TwitterException {
        AccessToken accessToken = new AccessToken(token, tokenSecret);
        Twitter twitter = new TwitterFactory(conf).getInstance(accessToken);
        twitter.updateStatus(message);
    }
View Full Code Here

        new ConfigurationBuilder().setJSONStoreEnabled(true).build())
        .getInstance();

    twitterStream.addListener(listener);
    twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
    AccessToken token = new AccessToken(accessToken, accessTokenSecret);
    twitterStream.setOAuthAccessToken(token);
   
    if (keyWords.length == 0) {

      twitterStream.sample();
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

            if (controlOperation.equals("GET_OAUTH_REQUEST_URL")) {
                // get and store AuthURL in plugin config to be rederend on UI
                ctrlResult.getComplexResults().put(new PropertySimple("authorizationURL", getAuthorizationURL()));
            } else if (controlOperation.equals("GET_ACCESS_TOKEN")) {

                AccessToken accessToken = null;
                String pin = operationConfig.getSimpleValue("pin", null);

                log.debug("using PIN [" + pin + "]");

                if (pin != null && pin.length() > 0) {
                    accessToken = this.twitter.getOAuthAccessToken(requestToken, pin);
                } else {
                    accessToken = this.twitter.getOAuthAccessToken();
                }

                log.debug("ScreenName: " + twitter.getScreenName());
                log.debug("TwitterId: [" + twitter.verifyCredentials().getId() + "]");
                log.debug("token: [" + accessToken.getToken() + "]");
                log.debug("tokenSecret: [" + accessToken.getTokenSecret() + "]");

                // Save the accessToken for future use by this plugin.
                String filePath = storeAccessToken(accessToken);

                ctrlResult.getComplexResults().put(
                    new PropertySimple("accessToken", "token[" + accessToken.getToken() + "] tokenSecret["
                        + accessToken.getTokenSecret() + ""));
                ctrlResult.getComplexResults().put(new PropertySimple("twitterScreenName", twitter.getScreenName()));
                ctrlResult.getComplexResults().put(new PropertySimple("accessTokenFilePath", filePath));
            } else {
                ctrlResult.setError("Invalid Operation! Please Select a valid one.");
            }
View Full Code Here

        String accessTokenFilePath = preferences.getSimpleValue("accessTokenFilePath", "/path/to/token.ser");


        try {
            TwitterFactory tFactory = new TwitterFactory();
            AccessToken accessToken = restoreAccessToken(accessTokenFilePath);

            log.debug("loading accessToken from " + accessTokenFilePath);
            log.debug("token: [" + accessToken.getToken() + "]");
            log.debug("tokenSecret: [" + accessToken.getTokenSecret() + "]");

            Twitter twitter = tFactory.getInstance();
            twitter.setOAuthConsumer(consumerKey, consumerSecret);
            twitter.setOAuthAccessToken(accessToken);
View Full Code Here

        //use buffering
        InputStream file = new FileInputStream(tokenFilePath);
        InputStream buffer = new BufferedInputStream(file);
        ObjectInput input = new ObjectInputStream(buffer);

        AccessToken token = null;

        try {
            token = (AccessToken) input.readObject();
        } catch (ClassNotFoundException e) {
            log.error("Erro reading token from disk: ", e);
View Full Code Here

//insert the appropriate consumer key and consumer secret here

        twitter.setOAuthConsumer("TLGtvoeABqf2tEG4itTUaw",
                "nUJPxYR1qJmhX9SnWTBT0MzO7dIqUtNyVPfhg10wf0");
        RequestToken requestToken = twitter.getOAuthRequestToken();
        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) {
                    accessToken = twitter.getOAuthAccessToken(requestToken, pin);
                } else {
                    accessToken = twitter.getOAuthAccessToken();
                }
            } catch (TwitterException te) {
                if (401 == te.getStatusCode()) {
                    System.out.println("Unable to get the access token.");
                } else {
                    te.printStackTrace();
                }
            }
        }
        //persist to the accessToken for future reference.
        System.out.println(twitter.verifyCredentials().getId());
        System.out.println("token : " + accessToken.getToken());
        System.out.println("tokenSecret : " + accessToken.getTokenSecret());
        //storeAccessToken(twitter.verifyCredentials().getId() , accessToken);
        Status status = twitter.updateStatus(args[0]);
        System.out.println("Successfully updated the status to [" + status.getText() + "].");
        System.exit(0);
    }
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.