List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory(String configTreePath)
From source file:formel0api.Game.java
License:Open Source License
private void sendHighScoreToServer() { try {/*from w w w . j a va2s .c om*/ String now = this.javaDate2XmlDate(new Date()).toString(); StringBuffer xmlStr = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<highScoreRequestType \n" + " xmlns=\"http://big.tuwien.ac.at/we/highscore/data\" \n" + " xmlns:ssd=\"http://www.dbai.tuwien.ac.at/education/ssd/SS13/uebung/Tournament\">\n" + "\n" + " <UserKey>34EphAp2C4ebaswu</UserKey>\n" + " <ssd:tournament start-date=\"" + now + "\" end-date=\"" + now + "\" registration-deadline=\"" + now + "\">\n" + " <ssd:players>\n" + " <ssd:player username=\"" + this.getLeaderData().getName() + "\">\n" + " <ssd:date-of-birth>" + this.getFormattedDate(this.getLeaderData().getBirthday()) + "</ssd:date-of-birth>\n" + " <ssd:gender>" + this.getLeaderData().getSex() + "</ssd:gender>\n" + " </ssd:player>\n" + " </ssd:players>\n" + " <ssd:rounds>\n" + " <ssd:round number=\"0\">\n" + " <ssd:game date=\"" + now + "\" status=\"finished\" duration=\"" + this.getSpentTime() + "\" winner=\"" + this.getLeaderData().getName() + "\">\n" + " <ssd:players>\n" + " <ssd:player ref=\"" + this.getLeaderData().getName() + "\"/>\n" + " </ssd:players>\n" + " </ssd:game>\n" + " </ssd:round>\n" + " </ssd:rounds>\n" + " </ssd:tournament>\n" + "</highScoreRequestType>"); JAXBContext jaxbContext = JAXBContext.newInstance(HighScoreRequestType.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); HighScoreRequestType request = (HighScoreRequestType) jaxbUnmarshaller .unmarshal(new StreamSource(new StringReader(xmlStr.toString()))); PublishHighScoreService service = new PublishHighScoreService(); PublishHighScoreEndpoint endpoint = service.getPublishHighScorePort(); String uuid = endpoint.publishHighScore(request); Logger.getLogger(Game.class.getName()).log(Level.INFO, uuid); TwitterStatusMessage tmsg = new TwitterStatusMessage(this.getLeader().getName(), uuid, new Date()); (new ITwitterClient() { @Override public void publishUuid(TwitterStatusMessage message) throws Exception { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("GZ6tiy1XyB9W0P4xEJudQ") .setOAuthConsumerSecret("gaJDlW0vf7en46JwHAOkZsTHvtAiZ3QUd2mD1x26J9w") .setOAuthAccessToken("1366513208-MutXEbBMAVOwrbFmZtj1r4Ih2vcoHGHE2207002") .setOAuthAccessTokenSecret("RMPWOePlus3xtURWRVnv1TgrjTyK7Zk33evp4KKyA"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); twitter.updateStatus(message.toString()); } }).publishUuid(tmsg); message = "UUID " + uuid + " wurde auf Twitter verffentlicht"; } catch (JAXBException e) { Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, e); } catch (Failure e) { Logger.getLogger(Game.class.getName()).log(Level.SEVERE, e.getFaultInfo().getDetail()); } catch (Exception ex) { Logger.getLogger(Game.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:fr.istic.taa.jaxrs.StatusEndpoint.java
License:Apache License
@GET @Path("/postTweet") @Produces(MediaType.APPLICATION_JSON)//from w w w .j a v a 2 s . c om public String getTweet() throws IOException, TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("jUTzyyI3zjBqiKQqhfQyFeqpm") .setOAuthConsumerSecret("gMkOSO9EYqlzrnq35kdoZIqvX12sJwP1wHKMqo6uYbvq2q0LGl") .setOAuthAccessToken("89767958-C2cLIz69SpdR6wmQGdzE8rQSXAMzIVBpYOuaZGmHQ") .setOAuthAccessTokenSecret("oG7FQJMQsX2OHKxcaHjUxgZI94ZqUShGi0qCAsI50xfpZ"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); String latestStatus = "TEST55555555"; Status status = twitter.updateStatus(latestStatus); System.out.println("Successfully updated the status to [" + status.getText() + "]."); return "Successfully updated status to " + status.getText(); }
From source file:fr.istic.taa.jaxrs.StatusEndpoint.java
License:Apache License
@GET @Path("/sendTweet") @Produces(MediaType.APPLICATION_JSON)// w ww. j a v a 2 s. c o m public String sendTweet() throws IOException, TwitterException { ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("jUTzyyI3zjBqiKQqhfQyFeqpm") .setOAuthConsumerSecret("gMkOSO9EYqlzrnq35kdoZIqvX12sJwP1wHKMqo6uYbvq2q0LGl") .setOAuthAccessToken("89767958-C2cLIz69SpdR6wmQGdzE8rQSXAMzIVBpYOuaZGmHQ") .setOAuthAccessTokenSecret("oG7FQJMQsX2OHKxcaHjUxgZI94ZqUShGi0qCAsI50xfpZ"); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); String recipientId; recipientId = "@nassssssiim"; String message; message = "test"; DirectMessage message1 = twitter.sendDirectMessage(recipientId, message); System.out.println(" to @" + message1.getRecipientScreenName()); return " to @" + message1.getRecipientScreenName(); }
From source file:generatetwittertokens.GenerateTwitterTokens.java
License:Open Source License
public static void main(String[] args) { String username = ""; ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(); configurationBuilder.setOAuthConsumerKey(consumerKey); configurationBuilder.setOAuthConsumerSecret(consumerSecret); try {/*from ww w . j a v a 2s .co m*/ Twitter twitter = new TwitterFactory(configurationBuilder.build()).getInstance(); RequestToken requestToken = twitter.getOAuthRequestToken(); AccessToken accessToken = null; BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); while (accessToken == null) { System.out.println("PhantomBot Twitter API Connection Tool\r\n\r\n" + "This tool will request access to read and write to your Twitter account.\r\n" + "You will be presented with a URL to open in your local browser to approve\r\n" + "access, however, this application will attempt to launch a browser for\r\n" + "you automatically.\r\n\r\n" + "You will be presented with a PIN that you must provide back to this\r\n" + "application. After that is completed, Twitter will generate OAuth keys\r\n" + "which will be stored in the PhantomBot directory as twitter.txt.\r\n\r\n" + "Do keep this file safe! The keys are the same as a password to your Twitter\r\n" + "account!\r\n\r\n" + "You may regenerate the OAuth keys at any time if needed.\r\n"); System.out.println("Open the following URL in your browser if a browser does not automatically\r\n" + "launch within a few seconds:"); System.out.println(" " + requestToken.getAuthorizationURL() + "\r\n"); /* * Attempt to launch a local browser. Ignore exceptions, except if the URL is bad. */ try { Desktop.getDesktop().browse(new URI(requestToken.getAuthorizationURL())); } catch (UnsupportedOperationException ignore) { } catch (IOException ignore) { } catch (URISyntaxException e) { throw new AssertionError(e); } /* * Request the username from the user. */ username = ""; while (username.length() < 1) { System.out.print("Provide your Twitter username: "); try { username = bufferedReader.readLine(); } catch (IOException ex) { username = ""; System.out.println("Failed to read input. Please try again."); } } /* * Request the PIN from the user. */ String pin = ""; while (pin.length() < 1) { System.out.print("Enter the PIN provided by Twitter: "); try { pin = bufferedReader.readLine(); accessToken = twitter.getOAuthAccessToken(requestToken, pin); } catch (TwitterException ex) { if (ex.getStatusCode() == 401) { pin = ""; System.out.println("Twitter failed to provide access tokens. Please try again."); } else { System.out.println("Twitter returned an error:\r\n" + ex.getMessage()); System.exit(1); } } catch (IOException ex) { pin = ""; System.out.println("Failed to read input. Please try again."); } } } System.out.println("Twitter has provided PhantomBot with OAuth Access Tokens."); String twitterData = ""; try { twitterData = "# Twitter Configuration File\r\n" + "# Generated by PhantomBot GenerateTwitterTokens\r\n" + "# If new tokens are required, run the application again.\r\n" + "#\r\n" + "# PROTECT THIS FILE AS IF IT HAD YOUR TWITTER PASSWORD IN IT!\r\n" + "twitter_username=" + username + "\r\n" + "twitter_access_token=" + accessToken.getToken() + "\r\n" + "twitter_secret_token=" + accessToken.getTokenSecret() + "\r\n"; Files.write(Paths.get("./twitter.txt"), twitterData.getBytes(StandardCharsets.UTF_8), StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING); System.out.println("Data has been successfully stored in twitter.txt."); } catch (IOException ex) { System.out.println("Unable to create twitter.txt.\r\nPlease create with the following content:\r\n" + twitterData); System.exit(1); } } catch (TwitterException ex) { System.out.println("Twitter returned an error:\r\n" + ex.getMessage()); System.exit(1); } }
From source file:geo.GetGeoDetails.java
License:Apache License
/** * Usage: java twitter4j.examples.geo.GetGeoDetails [place id] * * @param args message//w ww . j av a2s .co m */ public static void main(String[] args) { String s = "939067979a7f3b95"; try { Twitter twitter = new TwitterFactory(Data.getConf().build()).getInstance(); Place place = twitter.getGeoDetails(s); System.out.println("name: " + place.getName()); System.out.println("country: " + place.getCountry()); System.out.println("country code: " + place.getCountryCode()); System.out.println("full name: " + place.getFullName()); System.out.println("id: " + place.getId()); System.out.println("place type: " + place.getPlaceType()); System.out.println("street address: " + place.getStreetAddress()); Place[] containedWithinArray = place.getContainedWithIn(); if (containedWithinArray != null && containedWithinArray.length != 0) { System.out.println(" contained within:"); for (Place containedWithinPlace : containedWithinArray) { System.out.println(" id: " + containedWithinPlace.getId() + " name: " + containedWithinPlace.getFullName()); } } System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to retrieve geo details: " + te.getMessage()); System.exit(-1); } }
From source file:gohai.simpletweet.SimpleTweet.java
License:Apache License
protected void createInstance() { ConfigurationBuilder cb = new ConfigurationBuilder(); if (oAuthConsumerKey != null) { cb.setOAuthConsumerKey(oAuthConsumerKey); }//from w w w .ja v a2 s . co m if (oAuthConsumerSecret != null) { cb.setOAuthConsumerSecret(oAuthConsumerSecret); } if (oAuthAccessToken != null) { cb.setOAuthAccessToken(oAuthAccessToken); } if (oAuthAccessTokenSecret != null) { cb.setOAuthAccessTokenSecret(oAuthAccessTokenSecret); } twitter = new TwitterFactory(cb.build()).getInstance(); }
From source file:GUI.Authorization.java
License:Open Source License
/** * Creates new form Authorization and configures Twitter4J in order to * log in with Twitter properly/*from w w w .ja v a2 s . c o m*/ */ public Authorization() { initComponents(); // Related to the window appearance this.setTitle("TQuest Login"); this.setLocationRelativeTo(null); // Hides the PIN-related controls pinField.setVisible(false); goButton.setVisible(false); infoLabel4.setVisible(false); // Twitter4J and app configuration configBuilder = new ConfigurationBuilder(); configBuilder.setDebugEnabled(rootPaneCheckingEnabled); configBuilder.setOAuthConsumerKey(OAuthCK); configBuilder.setOAuthConsumerSecret(OAuthCS); OAuthTwitter = new TwitterFactory(configBuilder.build()).getInstance(); try { requestToken = OAuthTwitter.getOAuthRequestToken(); System.out.println("Request token obtained succesfully"); authURL = requestToken.getAuthorizationURL(); } catch (TwitterException ex) { Logger.getLogger(Authorization.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:humbala.Bonbon.java
public Bonbon() { cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey("bY3RaVuqzxNCKzDwXBvA") .setOAuthConsumerSecret("NmheZVfBwch4kxV3zjdjKPJvnX2bS41etPcnnUuyA") .setOAuthAccessToken("71545295-oiuSiTfwjwxudUBn3hJs1OtgDm4HtUjeFb9cgwaEH") .setOAuthAccessTokenSecret("7IDOPyQAB04pGKexoXNo0PVq6l8GoZNlAcSs5PRxqQ1sE") .setHttpProxyHost("cache.itb.ac.id").setHttpProxyPort(8080).setHttpProxyUser("tirtawr") .setHttpProxyPassword("satepadang"); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance();// w w w .j av a 2s. com }
From source file:inujini_.hatate.sqlite.dao.AccountDao.java
License:MIT License
/** * ?Twitter?./*from ww w . j a v a2 s.c o m*/ * @param context * @return ?????????{@link Twitter} */ public static List<Twitter> getTwitter(Context context) { val q = new QueryBuilder().selectAll().from(MetaAccount.TBL_NAME).where().equal(MetaAccount.UseFlag, true) .toString(); val res = context.getResources(); val consumerKey = res.getString(R.string.consumer_key); val consumerSecret = res.getString(R.string.consumer_secret); return new DatabaseHelper(context).getList(q, context, new Func1<Cursor, Twitter>() { @Override public Twitter call(Cursor c) { return new TwitterFactory(new ConfigurationBuilder().setOAuthConsumerKey(consumerKey) .setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(c.getStringByMeta(MetaAccount.AccessToken)) .setOAuthAccessTokenSecret(c.getStringByMeta(MetaAccount.AccessSecret)) .setHttpConnectionTimeout(15000).setHttpReadTimeout(30000).build()).getInstance(); } }); }
From source file:io.warp10.script.functions.TWITTERDM.java
License:Apache License
@Override public Object apply(WarpScriptStack stack) throws WarpScriptException { ////from w w w .j a v a 2s .co m // Extract parameters // String text = stack.pop().toString(); String recipient = stack.pop().toString(); String accessSecret = stack.pop().toString(); String accessToken = stack.pop().toString(); String consumerSecret = stack.pop().toString(); String consumerKey = stack.pop().toString(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(consumerKey).setOAuthConsumerSecret(consumerSecret) .setOAuthAccessToken(accessToken).setOAuthAccessTokenSecret(accessSecret); TwitterFactory tf = new TwitterFactory(cb.build()); Twitter twitter = tf.getInstance(); try { twitter.sendDirectMessage(recipient, text); } catch (TwitterException te) { throw new WarpScriptException("Error while sending Twitter Direct Message", te); } return stack; }