List of usage examples for twitter4j Twitter setOAuthAccessToken
void setOAuthAccessToken(AccessToken accessToken);
From source file:TwitterPublisher.Connexions.TwitterInterface.java
/** * Publish the given message on twitter. * @param message/*from www . j av a 2 s .c o m*/ * @throws TwitterException */ public static void publish(String message) throws TwitterException { TwitterFactory factory = new TwitterFactory(); Twitter twitter = factory.getInstance(); twitter.setOAuthConsumer("vIZ097dCEeXqnYofk8N6qTw9E", "GdN2pVxNTHJNRBZltaeeCDSTRScQL1bjCzlIgDza2WVRGfZ5SC"); twitter.setOAuthAccessToken(new AccessToken("795590633918464001-NpyvUY0OylVbLNznVvoG98M8pMIaajv", "z1xR0jyHBbUsDioW3T7LIAC9b3FgTyvaGxgMSiGGn9cjR")); twitter.updateStatus(message); System.out.println("Twitter message has been published"); }
From source file:twitterswingclient.TwitterClient.java
private void updateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateActionPerformed // TODO add your handling code here: String consKey = "Your key"; String consSecret = "Your secret"; String accToken = "Your key"; String accSecret = "Your secret"; try {/*from w ww . j a v a 2 s .com*/ TwitterFactory twitterFactory = new TwitterFactory(); Twitter twitter = twitterFactory.getInstance(); twitter.setOAuthConsumer(consKey, consSecret); twitter.setOAuthAccessToken(new AccessToken(accToken, accSecret)); StatusUpdate statusUpdate = new StatusUpdate(status.getText()); statusUpdate.setMedia("Feeling great", new URL("http://media3.giphy.com/media/el1tH0BzEWm4w/giphy.gif").openStream()); Status stat = twitter.updateStatus(statusUpdate); textArea.append("status.toString() = " + stat.toString()); textArea.append("status.getInReplyToScreenName() = " + stat.getInReplyToScreenName()); textArea.append("status.getSource() = " + stat.getSource()); textArea.append("status.getText() = " + stat.getText()); textArea.append("status.getContributors() = " + Arrays.toString(stat.getContributors())); textArea.append("status.getCreatedAt() = " + stat.getCreatedAt()); textArea.append("status.getCurrentUserRetweetId() = " + stat.getCurrentUserRetweetId()); textArea.append("status.getGeoLocation() = " + stat.getGeoLocation()); textArea.append("status.getId() = " + stat.getId()); textArea.append("status.getInReplyToStatusId() = " + stat.getInReplyToStatusId()); textArea.append("status.getInReplyToUserId() = " + stat.getInReplyToUserId()); textArea.append("status.getPlace() = " + stat.getPlace()); textArea.append("status.getRetweetCount() = " + stat.getRetweetCount()); textArea.append("status.getRetweetedStatus() = " + stat.getRetweetedStatus()); textArea.append("status.getUser() = " + stat.getUser()); textArea.append("status.getAccessLevel() = " + stat.getAccessLevel()); textArea.append("status.getHashtagEntities() = " + Arrays.toString(stat.getHashtagEntities())); textArea.append("status.getMediaEntities() = " + Arrays.toString(stat.getMediaEntities())); if (stat.getRateLimitStatus() != null) { textArea.append("status.getRateLimitStatus().getLimit() = " + stat.getRateLimitStatus().getLimit()); textArea.append( "status.getRateLimitStatus().getRemaining() = " + stat.getRateLimitStatus().getRemaining()); textArea.append("status.getRateLimitStatus().getResetTimeInSeconds() = " + stat.getRateLimitStatus().getResetTimeInSeconds()); textArea.append("status.getRateLimitStatus().getSecondsUntilReset() = " + stat.getRateLimitStatus().getSecondsUntilReset()); textArea.append("status.getRateLimitStatus().getRemainingHits() = " + stat.getRateLimitStatus().getRemaining()); } textArea.append("status.getURLEntities() = " + Arrays.toString(stat.getURLEntities())); textArea.append("status.getUserMentionEntities() = " + Arrays.toString(stat.getUserMentionEntities())); } catch (IOException ex) { textArea.append("IO Exception"); } catch (TwitterException tw) { textArea.append("Twitter Exception"); } }
From source file:utils.GetTwitters.java
License:Open Source License
public Iterable<MessageTwitter> getMessages() { List<MessageTwitter> messages = new ArrayList<MessageTwitter>(20); if (LastUpdate.getInstance(compte).isUpdate()) { LOGGER.fine("Les messages twitter sont jour, envoie du contenu de la base de donne"); messages.addAll(MessageTwitter.findByCompte(compte)); } else {//w w w. j a va2 s . c o m LOGGER.fine("Les messages twitter ne sont pas jour, rcupration du contenu de twiter"); Twitter twitter = getFactory().getInstance(); twitter.setOAuthConsumer("9Jsib4k1uEMCWZqEHy1t1Q", "vLQQaog60gYRrPCC2bHeEZdod3JDSkTRI9W7r2cZIZ8"); twitter.setOAuthAccessToken(new AccessToken("225864007-Y11ZtDLq2LVZwMR3anKxPW9nR6dIGkLyFlOhdAMx", "GQ16L9QMhhzSiRT4xRia7B25011BoNsXUEgUyp0vKI")); ResponseList<Status> listeStatus; try { listeStatus = twitter.getUserTimeline("@" + compte); } catch (TwitterException e) { LOGGER.log(Level.SEVERE, "Erreur lors de l'accs twitter", e); return MessageTwitter.findByCompte(compte); } for (Status status : listeStatus) { messages.add(new MessageTwitter(status.getCreatedAt(), status.getText(), compte)); } MessageTwitter.deleteAll(); for (MessageTwitter message : messages) { message.save(); } } Collections.sort(messages, new Comparator<MessageTwitter>() { public int compare(MessageTwitter o1, MessageTwitter o2) { return o2.getDateCreation().compareTo(o1.getDateCreation()); } }); return messages; }