List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory(String configTreePath)
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
public void connect() throws TwitterException { initProperties();// w w w . j a va 2s . c om ConfigurationBuilder config = new ConfigurationBuilder(); config.setOAuthConsumerKey(getOauthKey()); config.setOAuthConsumerSecret(getOauthSecret()); config.setOAuthAccessToken(getToken()); config.setOAuthAccessTokenSecret(getTokenSecret()); twitter4j.Twitter twitter = new TwitterFactory(config.build()).getInstance(); User user = twitter.verifyCredentials(); if (!this.userName.equals(user.getScreenName())) { this.userName = user.getScreenName(); saveProperties(null); } //AccessToken accessToken = new AccessToken(getToken(), getTokenSecret()); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(accessToken); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getOauthKey(), getOauthSecret(), accessToken); //twitter4j.Twitter twitter = new TwitterFactory().getInstance(getUsername(), getPassword()); setConnection(twitter); }
From source file:org.brunocvcunha.taskerbox.impl.twitter.TwitterChannel.java
License:Apache License
@Override public void setup() throws IllegalStateException, TwitterException { logInfo(log, "Twitter setup..."); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(this.consumerKey).setOAuthConsumerSecret(this.consumerSecret) .setOAuthAccessToken(this.accessToken).setOAuthAccessTokenSecret(this.accessTokenSecret); TwitterFactory tf = new TwitterFactory(cb.build()); this.twitter = tf.getInstance(); this.loggedUser = this.twitter.getScreenName(); logInfo(log, "Twitter setup finished! Logged user is " + this.loggedUser); }
From source file:org.btcwolf.twitter.TwitterAgent.java
License:Open Source License
public TwitterAgent() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(SettingsProvider.getProperty(CONSUMER_KEY)) .setOAuthConsumerSecret(SettingsProvider.getProperty(CONSUMER_SECRET)) .setOAuthAccessToken(SettingsProvider.getProperty(ACCESS_TOKEN)) .setOAuthAccessTokenSecret(SettingsProvider.getProperty(TOKEN_SECRET)); this.twitter = new TwitterFactory(cb.build()); }
From source file:org.codice.ddf.catalog.twitter.source.TwitterSource.java
License:Open Source License
public void init() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); Configuration configuration = configurationBuilder.setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret).setApplicationOnlyAuthEnabled(true).build(); twitterFactory = new TwitterFactory(configuration); }
From source file:org.craftercms.cstudio.publishing.processor.TwitterPostProcessor.java
License:Open Source License
/** * factory method for twitter instance. Override if you want to authenticate differently * @return twitter instance//from w w w .j ava2 s.c o m */ protected Twitter getTwitterInstance() { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setDebugEnabled(true).setOAuthConsumerKey(consumerKeyStr).setOAuthConsumerSecret(consumerSecretStr) .setOAuthAccessToken(accessTokenStr).setOAuthAccessTokenSecret(accessTokenSecretStr); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); Twitter twitter = factory.getInstance(); return twitter; }
From source file:org.csp.everyaware.internet.TwitterManager.java
License:Open Source License
public void initTwitter() { ConfigurationBuilder confbuilder = new ConfigurationBuilder(); Configuration conf = confbuilder.setOAuthConsumerKey(Constants.CONSUMER_KEY) .setOAuthConsumerSecret(Constants.CONSUMER_SECRET).build(); mTwitter = new TwitterFactory(conf).getInstance(); mTwitter.setOAuthAccessToken(null);/*from w w w . ja v a2s . c om*/ //try //{ new OuthRequestTokenTask().execute(Constants.CALLBACK_URL); /* mRequestToken = mTwitter.getOAuthRequestToken(Constants.CALLBACK_URL); Intent intent = new Intent(mActivity, TwitterLogin.class); intent.putExtra(Constants.IEXTRA_AUTH_URL, mRequestToken.getAuthorizationURL()); mActivity.startActivityForResult(intent, 0);*/ /* } catch (TwitterException e) { e.printStackTrace(); }*/ }
From source file:org.encuestame.social.api.templates.TwitterAPITemplate.java
License:Apache License
/** * Get OAuthorized Token./*from w ww .j ava 2 s . co m*/ * @param socialTwitterAccount {@link SocialAccount}. * @return {@link Twitter}. */ private Twitter getOAuthAuthorizedInstance() { final TwitterFactory tf = new TwitterFactory(this.configurationBuilder.build()); final Twitter twitter = tf.getInstance(); return twitter; }
From source file:org.fossasia.phimpme.share.twitter.HelperMethods.java
License:Apache License
public static void postToTwitterWithImage(Context context, final String imageUrl, final String message, final String token, final String secret, final TwitterCallback postResponse) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); configurationBuilder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); configurationBuilder.setOAuthAccessToken(token); configurationBuilder.setOAuthAccessTokenSecret(secret); Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); final File file = new File(imageUrl); boolean success = true; if (file.exists()) { try {//from w ww . j av a 2 s . co m StatusUpdate status = new StatusUpdate(message); status.setMedia(file); twitter.updateStatus(status); } catch (TwitterException e) { e.printStackTrace(); success = false; } } else { Log.d(TAG, "----- Invalid File ----------"); success = false; } postResponse.onFinsihed(success); }
From source file:org.fossasia.phimpme.share.twitter.LoginActivity.java
License:Apache License
private void askOAuth() { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY); configurationBuilder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET); Configuration configuration = configurationBuilder.build(); twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { @Override/*from ww w . j a va2 s . c o m*/ public void run() { try { requestToken = twitter.getOAuthRequestToken(AppConstant.TWITTER_CALLBACK_URL); } catch (Exception e) { final String errorString = e.toString(); LoginActivity.this.runOnUiThread(new Runnable() { @Override public void run() { dialog.dismiss(); SnackBarHandler.show(parentView, errorString); finish(); } }); return; } LoginActivity.this.runOnUiThread(new Runnable() { @Override public void run() { twitterLoginWebView.loadUrl(requestToken.getAuthenticationURL()); } }); } }).start(); }
From source file:org.gameontext.auth.twitter.TwitterAuth.java
License:Apache License
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ConfigurationBuilder c = new ConfigurationBuilder(); c.setOAuthConsumerKey(key).setOAuthConsumerSecret(secret); Twitter twitter = new TwitterFactory(c.build()).getInstance(); request.getSession().setAttribute("twitter", twitter); try {// w w w .j ava 2 s.com // twitter will tell the users browser to go to this address once // they are done authing. String callbackURL = authURL + "/TwitterCallback"; // to initiate an auth request, twitter needs us to have a request // token. RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL); // stash the request token in the session. request.getSession().setAttribute("requestToken", requestToken); // send the user to twitter to be authenticated. response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { throw new ServletException(e); } }