Example usage for twitter4j.auth AccessToken AccessToken

List of usage examples for twitter4j.auth AccessToken AccessToken

Introduction

In this page you can find the example usage for twitter4j.auth AccessToken AccessToken.

Prototype

public AccessToken(String token, String tokenSecret) 

Source Link

Usage

From source file:net.jeremybrooks.suprsetr.twitter.TwitterHelper.java

License:Open Source License

/**
 * Determine if the user has been authorized.
 * If the user is authorized, ensure that the Twitter object exists and has the required OAuth token.
 *
 * @return true if the user is authorized, false otherwise.
 *//*from w  w w. ja  va  2 s . c o  m*/
public static boolean isAuthorized() {
    boolean authorized = true;

    String token = LookupDAO.getValueForKey(SSConstants.LOOKUP_KEY_TWITTER_TOKEN);

    if (token == null || token.isEmpty()) {
        authorized = false;
    } else {
        if (twitter == null) {
            AccessToken accessToken = new AccessToken(
                    LookupDAO.getValueForKey(SSConstants.LOOKUP_KEY_TWITTER_TOKEN),
                    LookupDAO.getValueForKey(SSConstants.LOOKUP_KEY_TWITTER_TOKEN_SECRET));
            twitter = twitterFactory.getInstance();
            twitter.setOAuthConsumer(Main.getPrivateProperty("TWITTER_CONSUMER_KEY"),
                    Main.getPrivateProperty("TWITTER_CONSUMER_SECRET"));
            twitter.setOAuthAccessToken(accessToken);
        }
    }

    return authorized;
}

From source file:net.lacolaco.smileessence.twitter.TwitterApi.java

License:Open Source License

public Twitter getTwitter() {
    Twitter twitter = new TwitterFactory().getInstance();
    twitter.setOAuthAccessToken(new AccessToken(token, tokenSecret));
    return twitter;
}

From source file:net.lacolaco.smileessence.twitter.TwitterApi.java

License:Open Source License

public TwitterStream getTwitterStream() {
    TwitterStream stream = new TwitterStreamFactory().getInstance();
    stream.setOAuthAccessToken(new AccessToken(token, tokenSecret));
    return stream;
}

From source file:net.nitram509.twitter.TwitterService.java

License:Open Source License

private AccessToken createAccessTokenFor(UserId userId) {
    final UserProfile user = gatewayRepository.getUser(userId);
    return new AccessToken(user.getAccessToken(), user.getAccessTokenSecret());
}

From source file:nz.co.lolnet.james137137.lolnettwitchaddonbc.TwitterAPI.java

public TwitterAPI() {
    //Instantiate a re-usable and thread-safe factory
    TwitterFactory twitterFactory = new TwitterFactory();

    //Instantiate a new Twitter instance
    twitter = twitterFactory.getInstance();

    //setup OAuth Consumer Credentials
    twitter.setOAuthConsumer(consumerKey, consumerSecret);

    //setup OAuth Access Token
    twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
}

From source file:org.addhen.smssync.data.twitter.TwitterClient.java

License:Open Source License

@Nullable
public Status tweet(@NonNull String update) {
    if (mTwitterSessionManager != null && mTwitterSessionManager.getActiveSession() != null) {
        TwitterAuthToken authToken = mTwitterSessionManager.getActiveSession().getAuthToken();
        AccessToken accessToken = new AccessToken(authToken.token, authToken.secret);
        Twitter twitter = mTwitterFactory.getInstance(accessToken);
        StatusUpdate latestStatus = new StatusUpdate(update);
        try {/*from   ww  w  . j  a  v  a  2s. c  om*/
            return twitter.updateStatus(latestStatus);
        } catch (TwitterException e) {
            e.printStackTrace();
        }
    }
    return null;
}

From source file:org.apache.flume.sink.solr.morphline.TwitterSource.java

License:Apache License

@Override
public void configure(Context context) {
    String consumerKey = context.getString("consumerKey");
    String consumerSecret = context.getString("consumerSecret");
    String accessToken = context.getString("accessToken");
    String accessTokenSecret = context.getString("accessTokenSecret");

    LOGGER.info("Consumer Key:        '" + consumerKey + "'");
    LOGGER.info("Consumer Secret:     '" + consumerSecret + "'");
    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();/*from   w  w  w  . j  a va 2 s .  c o  m*/

    maxBatchSize = context.getInteger("maxBatchSize", maxBatchSize);
    maxBatchDurationMillis = context.getInteger("maxBatchDurationMillis", maxBatchDurationMillis);
}

From source file:org.apache.flume.source.twitter.TwitterSource.java

License:Apache License

@Override
public void configure(Context context) {
    String consumerKey = context.getString("consumerKey");
    String consumerSecret = context.getString("consumerSecret");
    String accessToken = context.getString("accessToken");
    String accessTokenSecret = context.getString("accessTokenSecret");

    LOGGER.info("Consumer Key:        '" + consumerKey + "'");
    LOGGER.info("Consumer Secret:     '" + consumerSecret + "'");
    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();//  w w w.  j  a  v a  2s  .  c  o  m
    dataFileWriter = new DataFileWriter<GenericRecord>(new GenericDatumWriter<GenericRecord>(avroSchema));

    maxBatchSize = context.getInteger("maxBatchSize", maxBatchSize);
    maxBatchDurationMillis = context.getInteger("maxBatchDurationMillis", maxBatchDurationMillis);
}

From source file:org.apache.storm.starter.spout.Q2TwitterSampleSpout.java

License:Apache License

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    queue = new LinkedBlockingQueue<Status>(1000);
    _collector = collector;/*from  w  w w .j  a v a  2  s.com*/

    StatusListener listener = new StatusListener() {

        @Override
        public void onStatus(Status status) {

            queue.offer(status);
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice sdn) {
        }

        @Override
        public void onTrackLimitationNotice(int i) {
        }

        @Override
        public void onScrubGeo(long l, long l1) {
        }

        @Override
        public void onException(Exception ex) {
        }

        @Override
        public void onStallWarning(StallWarning arg0) {
            // TODO Auto-generated method stub

        }

    };

    _twitterStream = new TwitterStreamFactory(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();
    }

    else {

        FilterQuery query = new FilterQuery().track(keyWords);
        query.language(new String[] { "en" });
        query.track(new String[] { "job", "vote", "local", "Clinton", "Trump", "debate", "tech",
                "TheWalkingDead", "android", "Election", "USA", "GOT7", "Empire", "Apple", "ISIS", "election",
                "Football", "iPhone", "Amazon", "uber" });
        _twitterStream.filter(query);
    }

}

From source file:org.csp.everyaware.internet.TwitterManager.java

License:Open Source License

public void postMessage(Record annotatedRecord) {
    SharedPreferences pref = mActivity.getApplicationContext().getSharedPreferences(Constants.PREF_NAME,
            mActivity.getApplicationContext().MODE_PRIVATE);
    String accessToken = pref.getString(Constants.PREF_KEY_ACCESS_TOKEN, null);
    String accessTokenSecret = pref.getString(Constants.PREF_KEY_ACCESS_TOKEN_SECRET, null);
    if (accessToken == null || accessTokenSecret == null) {
        Toast.makeText(mActivity.getApplicationContext(), "not authorize yet", Toast.LENGTH_SHORT).show();
        return;// w  w w.  jav a  2  s . co m
    }
    mTwitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));

    String status = composeMessage(annotatedRecord);

    //do twitter update status in async task
    new PostMessageTask().execute(status);
}