List of usage examples for twitter4j.conf ConfigurationBuilder setDebugEnabled
public ConfigurationBuilder setDebugEnabled(boolean debugEnabled)
From source file:au.com.infiniterecursion.hashqanda.MainActivity.java
public boolean loadTweets() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("Q2DfeCNOxprbDp66fWlw") .setOAuthConsumerSecret("TgyJ26CKXz1SxGiEJx4HG9rytFsqiMZlEPeCO7S9g"); Twitter twitter = new TwitterFactory(cb.build()).getInstance(); // clear tweet list. MainActivity.this.runOnUiThread(new Runnable() { public void run() { // add to it , via the runOnUIThread app.getTweetList().clear();/*from w w w . j av a 2s . c o m*/ } }); try { Log.d(TAG, " starting Tweets loading "); Query q = new Query("#qanda"); q.setRpp(numberTweets); QueryResult result = twitter.search(q); List<Tweet> tweets = result.getTweets(); for (Tweet tweet : tweets) { // Log.d(TAG, "@" + tweet.getFromUser() + " - " + // tweet.getText()); // Log.d(TAG, " img url " + tweet.getProfileImageUrl()); final CachedBitmapAndTweet cachedbmtwt = new CachedBitmapAndTweet(); cachedbmtwt.twt = tweet; try { URL url = new URL(tweet.getProfileImageUrl()); InputStream is = (InputStream) url.getContent(); if (is != null) { Bitmap bitmap = BitmapFactory.decodeStream(is); cachedbmtwt.bm = bitmap; } else { cachedbmtwt.bm = null; } } catch (MalformedURLException e) { e.printStackTrace(); cachedbmtwt.bm = null; } catch (IOException e) { e.printStackTrace(); cachedbmtwt.bm = null; } catch (NullPointerException npe) { npe.printStackTrace(); cachedbmtwt.bm = null; } MainActivity.this.runOnUiThread(new Runnable() { public void run() { // add to it , via the runOnUIThread app.getTweetList().add(cachedbmtwt); } }); } Log.d(TAG, " finished Tweets loading "); return true; } catch (TwitterException te) { te.printStackTrace(); Log.d(TAG, "Failed to search tweets: " + te.getMessage()); return false; } }
From source file:bditac.TwitterCaptura.java
public static void main(String[] args) throws TwitterException { int criid, apiid, capid; if (args.length == 3) { criid = Integer.parseInt(args[0]); apiid = Integer.parseInt(args[1]); capid = Integer.parseInt(args[2]); } else {// ww w . j a v a 2 s. c om criid = 1; apiid = 1; capid = 1; } CriseJpaController crijpa = new CriseJpaController(factory); Crise crise = crijpa.findCrise(criid); CriseApiJpaController criapijpa = new CriseApiJpaController(factory); CriseApi criapi = criapijpa.findCriseApi(capid); ApiJpaController apijpa = new ApiJpaController(factory); Api api = apijpa.findApi(apiid); CidadeJpaController cidjpa = new CidadeJpaController(factory); Cidade cidade = cidjpa.findCidade(crise.getCidId()); String coords[] = crise.getCriRegiao().split(","); TwitterGeo geo = new TwitterGeo(coords, cidade.getCidNome(), crise.getCriGeotipo()); Thread threadGeo = new Thread(geo); TwitterMens mens = new TwitterMens(crise.getCrtId()); Thread threadMens = new Thread(mens); TwitterGravar gravar = new TwitterGravar(); Thread threadGravar = new Thread(gravar); threadGeo.setName("ThreadGeo"); threadGeo.start(); threadMens.setName("ThreadMens"); threadMens.start(); threadGravar.setName("ThreadGravar"); threadGravar.start(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(criapi.getCapKey()) .setOAuthConsumerSecret(criapi.getCapSecret()).setOAuthAccessToken(criapi.getCapToken()) .setOAuthAccessTokenSecret(criapi.getCapTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); String texto = "[\\xF0\\x9F]"; StatusListener listener; listener = new StatusListener() { int cont = 0; @Override public void onStatus(Status status) { if (!(status.getText().contains(texto) || status.getText().isEmpty())) { Ocorrencia ocor = new Ocorrencia(); ocor.setApiId(apiid); ocor.setCriId(criid); ocor.setCapId(capid); ocor.setOcrIdApi(status.getId()); ocor.setOcrCriacao(status.getCreatedAt()); ocor.setOcrTexto(status.getText()); // System.out.println(ocor.getOcrTexto()); ocor.setOcrUsuId(status.getUser().getId()); ocor.setOcrUsuNome(status.getUser().getName()); ocor.setOcrUsuScreenNome(status.getUser().getScreenName()); ocor.setOcrFonte(status.getSource()); ocor.setOcrLingua(status.getLang()); ocor.setOcrFavorite(status.getFavoriteCount()); ocor.setOcrRetweet(status.getRetweetCount()); String coords = ""; if (status.getPlace() == null) { ocor.setOcrPaisCodigo(""); ocor.setOcrPais(""); ocor.setOcrLocal(""); } else { ocor.setOcrPaisCodigo(status.getPlace().getCountryCode()); ocor.setOcrPais(status.getPlace().getCountry()); ocor.setOcrLocal(status.getPlace().getFullName()); GeoLocation locs[][] = status.getPlace().getBoundingBoxCoordinates(); for (int x = 0; x < locs.length; x++) { for (int y = 0; y < locs[x].length; y++) { coords += "[" + locs[x][y].getLongitude() + "," + locs[x][y].getLatitude() + "]"; if (!(x == locs.length - 1 && y == locs[x].length - 1)) { coords += ","; } } } } ocor.setOcrCoordenadas(coords); ocor.setOcrGeo('0'); ocor.setOcrIdentificacao('0'); ocor.setOcrIdenper(0.0f); ocor.setOcrGravado('0'); ocor.setOcrSentimento('0'); ocor.setOcrTempo('0'); boolean add = ocors.add(ocor); cont++; if (ocors.size() > 1000) { Limpar(); } // System.out.println(cont+" - "+status.getId() + " - " + status.getCreatedAt() + status.getPlace().getFullName()); } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } private void Limpar() { while (!threadGeo.isInterrupted()) { threadGeo.interrupt(); } while (!threadMens.isInterrupted()) { threadMens.interrupt(); } while (!threadGravar.isInterrupted()) { threadGravar.interrupt(); } boolean achou = true; int x = 0; System.out.println("Removendo: " + ocors.size()); while (x < ocors.size()) { if (ocors.get(x).getOcrGravado() != '0') { ocors.remove(x); } else { x++; } } System.out.println("Final: " + ocors.size()); if (!threadGeo.isAlive()) { threadGeo.start(); } if (!threadMens.isAlive()) { threadMens.start(); } if (!threadGravar.isAlive()) { threadGravar.start(); } } }; FilterQuery filter = new FilterQuery(); double[][] location = new double[2][2]; location[0][0] = Double.parseDouble(coords[0]); location[0][1] = Double.parseDouble(coords[1]); location[1][0] = Double.parseDouble(coords[4]); location[1][1] = Double.parseDouble(coords[5]); filter.locations(location); twitterStream.addListener(listener); twitterStream.filter(filter); }
From source file:benche.me.TwitterParser.Main.java
License:Open Source License
/** * Configure twitter API connection for historical search * @return Twitter connection instance */// ww w . j a v a2 s. co m private static Twitter configureSearch() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(Constants.CONSUMER_KEY_KEY) .setOAuthConsumerSecret(Constants.CONSUMER_SECRET_KEY) .setOAuthAccessToken(Constants.ACCESS_TOKEN_KEY) .setOAuthAccessTokenSecret(Constants.ACCESS_TOKEN_SECRET_KEY); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); return twitter; }
From source file:clientetwitter.ClienteTwitter.java
public static void PostInTimeLine(String texto) throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("xxxxxxxxxxxx") //to get all the OAuth go to apps.twitter.com .setOAuthConsumerSecret("xxxxxxxxxxxxxxxx").setOAuthAccessToken("xxxxxxxxxxxxxxxxxxxxxxx") .setOAuthAccessTokenSecret("xxxxxxxxxxxxxxxxxxxx"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); //posting//ww w.j a v a 2s . c o m Status stat = tw.updateStatus(texto); System.out.println("Posted"); }
From source file:clientetwitter.ClienteTwitter.java
public static void ReadTimeLine() throws TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("ZpF1TSpAyQlBLMN7egUz3uT3D") .setOAuthConsumerSecret("r2icg36QB6G862Re2IvwHNGuDK25z5awKSeNG9kV9LRpcAmuOW") .setOAuthAccessToken("4314010284-QGXKFbFQ5TK4zqbplRsfoP0wL6NTv7bsMJypWex") .setOAuthAccessTokenSecret("4v61YXTkzM3Kob0xAHu59ISgM0fTKSLrOuDXTG5ctX7rr"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter4j.Twitter tw = tf.getInstance(); //reading/*from ww w .j a v a 2 s.com*/ List<Status> statuses = tw.getHomeTimeline(); for (Status status1 : statuses) { System.out.println(status1.getUser().getName() + ": " + status1.getText()); } }
From source file:cloudcomputebot.Twitter.TwitterLib.java
License:Open Source License
public static void init() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("yZpAVykzcxwyohWOVBwuFaaaB") .setOAuthConsumerSecret("tXZQzYPeh1YmxGUPYotaKFoeLKeI6m8dAPgPh60l4mSltmMpxw") .setOAuthAccessToken("4741197613-i0WRUBMg1oGM2JR6GWnAztKs60u8lhMBhlr8TXD") .setOAuthAccessTokenSecret("H4EMPCNPV0NkTom3aUZB8J2uOaWnYHC28vxyTZ1bCvpd6"); TwitterFactory tf = new TwitterFactory(cb.build()); t = tf.getInstance();//w w w. j a va2 s . c o m }
From source file:co.cask.cdap.template.etl.realtime.source.TwitterSource.java
License:Apache License
@Override public void initialize(RealtimeContext context) throws Exception { super.initialize(context); // Disable chatty logging from twitter4j. System.setProperty("twitter4j.loggerFactory", "twitter4j.NullLoggerFactory"); Schema.Field idField = Schema.Field.of(ID, Schema.of(Schema.Type.LONG)); Schema.Field msgField = Schema.Field.of(MSG, Schema.of(Schema.Type.STRING)); Schema.Field langField = Schema.Field.of(LANG, Schema.nullableOf(Schema.of(Schema.Type.STRING))); Schema.Field timeField = Schema.Field.of(TIME, Schema.nullableOf(Schema.of(Schema.Type.LONG))); Schema.Field favCount = Schema.Field.of(FAVC, Schema.of(Schema.Type.INT)); Schema.Field rtCount = Schema.Field.of(RTC, Schema.of(Schema.Type.INT)); Schema.Field sourceField = Schema.Field.of(SRC, Schema.nullableOf(Schema.of(Schema.Type.STRING))); Schema.Field geoLatField = Schema.Field.of(GLAT, Schema.nullableOf(Schema.of(Schema.Type.DOUBLE))); Schema.Field geoLongField = Schema.Field.of(GLNG, Schema.nullableOf(Schema.of(Schema.Type.DOUBLE))); Schema.Field reTweetField = Schema.Field.of(ISRT, Schema.of(Schema.Type.BOOLEAN)); schema = Schema.recordOf("tweet", idField, msgField, langField, timeField, favCount, rtCount, sourceField, geoLatField, geoLongField, reTweetField); statusListener = new StatusListener() { @Override/*from w w w . j a va 2 s .c om*/ public void onStatus(Status status) { tweetQ.add(status); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // No-op } @Override public void onTrackLimitationNotice(int i) { // No-op } @Override public void onScrubGeo(long l, long l1) { // No-op } @Override public void onStallWarning(StallWarning stallWarning) { // No-op } @Override public void onException(Exception e) { // No-op } }; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(false).setOAuthConsumerKey(twitterConfig.consumerKey) .setOAuthConsumerSecret(twitterConfig.consumeSecret).setOAuthAccessToken(twitterConfig.accessToken) .setOAuthAccessTokenSecret(twitterConfig.accessTokenSecret); twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); twitterStream.addListener(statusListener); twitterStream.sample(); }
From source file:co.cask.hydrator.plugin.realtime.source.TwitterSource.java
License:Apache License
@Override public void initialize(RealtimeContext context) throws Exception { super.initialize(context); // Disable chatty logging from twitter4j. System.setProperty("twitter4j.loggerFactory", "twitter4j.NullLoggerFactory"); statusListener = new StatusListener() { @Override/*from www.j a v a 2s .co m*/ public void onStatus(Status status) { tweetQ.add(status); } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { // No-op } @Override public void onTrackLimitationNotice(int i) { // No-op } @Override public void onScrubGeo(long l, long l1) { // No-op } @Override public void onStallWarning(StallWarning stallWarning) { // No-op } @Override public void onException(Exception e) { // No-op } }; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setDebugEnabled(false).setOAuthConsumerKey(twitterConfig.consumerKey) .setOAuthConsumerSecret(twitterConfig.consumeSecret).setOAuthAccessToken(twitterConfig.accessToken) .setOAuthAccessTokenSecret(twitterConfig.accessTokenSecret); twitterStream = new TwitterStreamFactory(configurationBuilder.build()).getInstance(); twitterStream.addListener(statusListener); twitterStream.sample(); }
From source file:co.thehotnews.lambda.TheHotNewsSpeechlet.java
License:Open Source License
public TheHotNewsSpeechlet() { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(TWITTER_OAUTH_CONSUMER_KEY) .setOAuthConsumerSecret(TWITTER_OAUTH_CONSUMER_SECRET) .setOAuthAccessToken(TWITTER_OAUTH_ACCESS_TOKEN) .setOAuthAccessTokenSecret(TWITTER_OAUTH_ACCESS_TOKEN_SECRET); twitterFactory = new TwitterFactory(cb.build()); }
From source file:cojoytuerto.TAuth.java
public TAuth() throws IOException, TwitterException { //Constructor de la clase File file = new File("auth_file.txt"); if (!file.exists()) { ConfigurationBuilder configBuilder = new ConfigurationBuilder(); configBuilder.setDebugEnabled(true).setOAuthConsumerKey("wCWSOW8xHlxfQq24kSxXuXNm9") .setOAuthConsumerSecret("5B1R4bxZv7TcO7Vmq3NvhM3Bo3YcO0qCIJP2vDD9HnOaPL63YD"); configBuilder.setHttpProxyHost("127.0.0.1"); configBuilder.setUseSSL(true);//w w w .j av a2 s. co m configBuilder.setHttpProxyPort(3128); Twitter OAuthTwitter = new TwitterFactory(configBuilder.build()).getInstance(); RequestToken requestToken = null; AccessToken accessToken = null; String url = null; do { try { requestToken = OAuthTwitter.getOAuthRequestToken(); System.out.println("Request Token obtenido con xito."); System.out.println("Request Token: " + requestToken.getToken()); System.out.println("Request Token secret: " + requestToken.getTokenSecret()); url = requestToken.getAuthorizationURL(); url = url.replace("http://", "https://"); System.out.println("URL:"); System.out.println(url); } catch (TwitterException ex) { Logger.getLogger(TAuth.class.getName()).log(Level.SEVERE, null, ex); } BufferedReader lectorTeclado = new BufferedReader(new InputStreamReader(System.in)); //Abro el navegador. Firefox, en este caso. Runtime runtime = Runtime.getRuntime(); try { runtime.exec("firefox " + url); } catch (Exception e) { } //Nos avisa de que introduciremos el PIN a continuacin System.out.print("Introduce el PIN del navegador y pulsa intro.nn PIN: "); //Leemos el PIN // String pin = lectorTeclado.readLine(); String pin = JOptionPane.showInputDialog(null, "Introduce el PIN del navegador y pulsa intro.nn PIN: "); if (pin.length() > 0) { accessToken = OAuthTwitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = OAuthTwitter.getOAuthAccessToken(requestToken); } } while (accessToken == null); System.out.println("nnAccess Tokens obtenidos con xito."); System.out.println("Access Token: " + accessToken.getToken()); System.out.println("Access Token secret: " + accessToken.getTokenSecret()); FileOutputStream fileOS = null; // File file; String content = accessToken.getToken() + "\n" + accessToken.getTokenSecret(); try { // file = new File("auth_file.txt"); fileOS = new FileOutputStream(file); //Si el archivo no existe, se crea if (!file.exists()) { file.createNewFile(); } //Se obtiene el contenido en Bytes byte[] contentInBytes = content.getBytes(); fileOS.write(contentInBytes); fileOS.flush(); fileOS.close(); System.out.println("Escritura realizada con xito."); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fileOS != null) { fileOS.close(); } } catch (IOException e) { e.printStackTrace(); } } } }