List of usage examples for twitter4j.conf ConfigurationBuilder build
public Configuration build()
From source file:com.learnncode.demotwitterimagepost.HelperMethods.java
License:Apache License
public static void postToTwitterWithInputStream(Context context, final Activity callingActivity, final InputStream inputStream, final String message, final TwitterCallback postResponse) { if (!LoginActivity.isActive(context)) { postResponse.onFinsihed(false);/*from ww w .j a v a 2s . c o m*/ return; } final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder .setOAuthConsumerSecret(context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(LoginActivity.getAccessToken(context)); configurationBuilder.setOAuthAccessTokenSecret(LoginActivity.getAccessTokenSecret(context)); final Configuration configuration = configurationBuilder.build(); final Twitter twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { private double x; @Override public void run() { boolean success = true; try { x = Math.random(); if (inputStream != null) { final StatusUpdate status = new StatusUpdate(message); status.setMedia("GIF image", inputStream); twitter.updateStatus(status); } else { Log.d(TAG, "----- Invalid File ----------"); success = false; } } catch (final Exception e) { e.printStackTrace(); success = false; } final boolean finalSuccess = success; callingActivity.runOnUiThread(new Runnable() { @Override public void run() { postResponse.onFinsihed(finalSuccess); } }); } }).start(); }
From source file:com.learnncode.demotwitterimagepost.LoginActivity.java
License:Apache License
private void askOAuth() { final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(twitterConsumerKey); configurationBuilder.setOAuthConsumerSecret(twitterConsumerSecret); final Configuration configuration = configurationBuilder.build(); twitter = new TwitterFactory(configuration).getInstance(); new Thread(new Runnable() { @Override//from w w w . j av a2 s .c om public void run() { try { requestToken = twitter.getOAuthRequestToken(AppConstantTwitter.TWITTER_CALLBACK_URL); } catch (final Exception e) { final String errorString = e.toString(); LoginActivity.this.runOnUiThread(new Runnable() { @Override public void run() { if (busyDialog != null) { busyDialog.dismis(); } Toast.makeText(LoginActivity.this, errorString.toString(), Toast.LENGTH_SHORT).show(); finish(); } }); return; } LoginActivity.this.runOnUiThread(new Runnable() { @Override public void run() { twitterLoginWebView.loadUrl(requestToken.getAuthenticationURL()); } }); } }).start(); }
From source file:com.learnncode.twitter.Utilities.TwitterHelper.java
License:Apache License
public static Twitter getTwitterInstance(Context _Context) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(_Context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder/*from www . j ava 2 s . c o m*/ .setOAuthConsumerSecret(_Context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(AppSettings.getTwitterAccessToken((_Context))); configurationBuilder.setOAuthAccessTokenSecret(AppSettings.getTwitterAccessTokenSecret(_Context)); Configuration configuration = configurationBuilder.build(); return new TwitterFactory(configuration).getInstance(); }
From source file:com.learnncode.twitter.Utilities.TwitterHelper.java
License:Apache License
public static Twitter getTwitterInstanceWithoutAuthentication(Context _Context) { ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(_Context.getResources().getString(R.string.twitter_consumer_key)); configurationBuilder//from w ww . j a v a 2 s.co m .setOAuthConsumerSecret(_Context.getResources().getString(R.string.twitter_consumer_secret)); configurationBuilder.setOAuthAccessToken(_Context.getResources().getString(R.string.twitter_access_token)); configurationBuilder .setOAuthAccessTokenSecret(_Context.getResources().getString(R.string.twitter_access_token_secret)); Configuration configuration = configurationBuilder.build(); return new TwitterFactory(configuration).getInstance(); }
From source file:com.left8.evs.utilities.dsretriever.TweetsRetriever.java
License:Open Source License
/** * Method to retrieve and store historical tweets by collecting them with * their ID.//ww w .j a va 2 s . c om * @param tweetIDs The IDs of the tweets that are going to be collected. * @param mongoDB A MongoHandler object. * @param config A configuration object. * @param event The ground truth event for which the tweets that are going * to be collected, are referring to. */ public final void retrieveTweetsById(List<String> tweetIDs, MongoHandler mongoDB, Config config, String event) { ConfigurationBuilder cb = getAuthorization(); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); tweetIDs.stream().forEach((item) -> { try { //Get tweet and all its metadata and store it Status status = twitter.showStatus(Long.parseLong(item)); mongoDB.insertSingleTweetIntoMongoDB(status, event); } catch (TwitterException e) { Utilities.printMessageln("Failed to retrieve tweet with ID: " + item); Logger.getLogger(TweetsRetriever.class.getName()).log(Level.SEVERE, null, e); } }); }
From source file:com.left8.evs.utilities.dsretriever.TweetsRetriever.java
License:Open Source License
/** * Method that handles the Twitter streaming API. <br> * <b>WARNING:</b> Method does not terminate by itself, due to the fact that * the streamer runs in a different thread. * @param keywords The keywords for which the streamer searches for tweets. * @param mongoDB A handler for the MongoDB database. * @param config A configuration object. *///from www . j a v a 2s .co m public final void retrieveTweetsWithStreamingAPI(String[] keywords, MongoHandler mongoDB, Config config) { ConfigurationBuilder cb = getAuthorization(); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); final StatusListener listener; listener = new StatusListener() { @Override public final void onStatus(Status status) { //Insert tweet to MongoDB mongoDB.insertSingleTweetIntoMongoDB(status, "NULL"); } @Override public final void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { Utilities.printMessageln("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public final void onTrackLimitationNotice(int numberOfLimitedStatuses) { Utilities.printMessageln("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public final void onScrubGeo(long userId, long upToStatusId) { Utilities.printMessageln("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public final void onStallWarning(StallWarning warning) { Utilities.printMessageln("Got stall warning:" + warning); } @Override public final void onException(Exception ex) { ex.printStackTrace(System.out); } }; FilterQuery fq = new FilterQuery(); fq.language("en"); //Set language of tweets to "English" fq.track(keywords); //Load the search terms twitterStream.addListener(listener); //Start listening to the stream twitterStream.filter(fq); //Apply the search filters }
From source file:com.marpies.ane.twitter.data.TwitterAPI.java
License:Apache License
/** * * * Public API//from w w w . j a v a 2s.co m * * */ public static void init(String consumerKey, String consumerSecret, String urlScheme) { if (mIsInitialized) return; mURLScheme = urlScheme; ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(consumerKey); builder.setOAuthConsumerSecret(consumerSecret); mConfiguration = builder.build(); mIsInitialized = true; }
From source file:com.michaelstark.twitteroauth.LoginServlet.java
/** * Handles the HTTP <code>POST</code> method. * Begins the OAuth authentication mechanism. * * @param request servlet request/* ww w. j a va2 s . co m*/ * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey("<consumer key goes here>") .setOAuthConsumerSecret("<consumer secret goes here>"); Twitter twitter = new TwitterFactory(builder.build()).getInstance(); HttpSession session = request.getSession(true); // Get the callback URL. String callbackUrl = String.format("http://%s:%d%s/oauth_callback", request.getServerName(), request.getServerPort(), request.getContextPath()); try { // Get the request token. RequestToken requestToken = twitter.getOAuthRequestToken(callbackUrl); // Store the request token for later use. session.setAttribute("requestToken", requestToken); // Save the Twitter client for later. session.setAttribute("twitterClient", twitter); // Redirect to Twitter authentication page. response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { logger.log(Level.SEVERE, "Could not login via Twitter: ", e); // Failure. Go back to home. Maybe add an error message. request.getRequestDispatcher("/index.jsp").forward(request, response); } }
From source file:com.mycompany.dovetune.SignIn.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w. j a va 2 s . co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Djgh7AmnNzxmv7fXzqlsdj8RB") .setOAuthConsumerSecret("Mnj40YllwKBBZvOkndnrmxl1TaNvcnS0x40PFhhDnMHysgzHum"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); request.getSession().setAttribute("twitter", twitter); try { StringBuffer callbackURL = request.getRequestURL(); System.out.println("TwitterLoginServlet:callbackURL:" + callbackURL); int index = callbackURL.lastIndexOf("/"); callbackURL.replace(index, callbackURL.length(), "").append("/Callback"); RequestToken requestToken = twitter.getOAuthRequestToken(callbackURL.toString()); request.getSession().setAttribute("requestToken", requestToken); System.out.println("requestToken.getAuthenticationURL():" + requestToken.getAuthenticationURL()); response.sendRedirect(requestToken.getAuthenticationURL()); } catch (TwitterException e) { throw new ServletException(e); } }
From source file:com.mycompany.mech2015task.App.java
public static void main(String[] args) throws Exception { ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(CONSUMER_KEY); builder.setOAuthConsumerSecret(CONSUMER_SECRET); builder.setOAuthAccessToken(ACCESS_TOKEN); builder.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); // ??Twitter4J??API???betastream.twitter.com??????? builder.setUserStreamBaseURL("https://userstream.twitter.com/2/"); // Configuration? Configuration configuration = builder.build(); /* Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY) .setOAuthConsumerSecret(CONSUMER_SECRET) .setOAuthAccessToken(ACCESS_TOKEN) .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET) .build();//from ww w . ja va 2s . c o m */ TwitterStream twStream = new TwitterStreamFactory(configuration).getInstance(); //TwitterStream twStream = new TwitterStreamFactory().getInstance(); twStream.addListener(new MyStatusListener()); twStream.user(); //twStream.sample(); }