List of usage examples for twitter4j Twitter setOAuthConsumer
void setOAuthConsumer(String consumerKey, String consumerSecret);
From source file:org.zoneproject.extractor.twitterreader.TwitterApi.java
License:Open Source License
public static ArrayList<Item> getFluxFromTimeline(String sourceUri) { ArrayList<Item> result = new ArrayList<Item>(); AccessToken userToken = TwitterApi.getAccessToken(sourceUri); Twitter twitter = factory.getInstance(); twitter.setOAuthConsumer(Config.getVar("Twitter-OAuth-customer"), Config.getVar("Twitter-OAuth-customerKey")); twitter.setOAuthAccessToken(userToken); ResponseList<Status> status;/* w w w. ja v a 2 s . c o m*/ try { status = twitter.getHomeTimeline(); for (Status r : status) { result.add(TwitterApi.getItemFromStatus(r, sourceUri)); } } catch (Exception ex) { logger.info(ex); } return result; }
From source file:ru.ideast.SocialServices.OAuthHelp.java
License:Apache License
/** * Depricated method has been used/*from www. j a v a2 s. co m*/ * * @param twitter */ public void configureOAuth(Twitter twitter) { try { twitter.setOAuthConsumer(consumerKey, consumerSecretKey); twitter.setOAuthAccessToken(accessToken); } catch (IllegalStateException e) { } }
From source file:se.aceone.housenews.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * //from w ww . j a va 2s. c o m * @param args * message */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); // get request token. // this will throw IllegalStateException if access token is already available twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); handleAccessToken(twitter); Status status = twitter.updateStatus(args[0] + " : " + System.currentTimeMillis()); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); } catch (IllegalStateException ie) { ie.printStackTrace(); // access token is already available, or consumer key/secret is not set. } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } catch (IOException ioe) { ioe.printStackTrace(); System.out.println("Failed to read the system input."); System.exit(-1); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:servlet.TwitterClient.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*from w ww . jav a2s . 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, TwitterException { String consumerKey = "acdi5Tpjda5dshPSgsNdc2YuP"; String consumerSecret = "5mZuFFShjXdwTCbk1hRZ9c47BJz9vKwoPFDPDHyG9xdxLGdZRi"; String accessToken = "224428346-hU7uwq12mUSvxT7jClIEnpCN5Lj6Rp1YgnQiwG6h"; String accessTokenSecret = "8kPqai6ciArmiWinkBOGvxHfYbif2OL7N96NbQYvEHfiH"; Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); AccessToken accessTok = new AccessToken(accessToken, accessTokenSecret); twitter.setOAuthAccessToken(accessTok); String action = (request.getParameter("action") != null) ? request.getParameter("action") : "fresh"; if (action.equalsIgnoreCase("Send")) { String latestStatus = request.getParameter("newTweet"); Status status = twitter.updateStatus(latestStatus); } //cargamos todos los tweets ResponseList<Status> a = twitter.getUserTimeline(new Paging(1, 20)); request.setAttribute("Tweets", a); //mandamos los tweets en una lista a la vista request.getRequestDispatcher("twitter.jsp").forward(request, response); }
From source file:tokyo.ryogo.dropkick.sns.twitter.DKTwitter.java
License:Apache License
public static Twitter getTwitterInstance(Context context) { String consumerKey = TwitterSecret.getTwitterConsumerKey(context.getString(R.string.cryption)); String consumerSecret = TwitterSecret.getTwitterConsumerKeySecret(context.getString(R.string.cryption)); TwitterFactory factory = new TwitterFactory(); Twitter twitter = factory.getInstance(); twitter.setOAuthConsumer(consumerKey, consumerSecret); if (hasAccessToken(context)) { twitter.setOAuthAccessToken(loadAccessToken(context)); }/* w ww.j a v a 2s .c om*/ return twitter; }
From source file:twitterbot.example.tweet.RetweetMethods.java
static public void RetweetTweet(String id) { try {/* w w w. j a va 2s . c o m*/ String consumerKey = ""; // key obtained after registering app. String consumerSecret = ""; // secret key obtained from the registered app. String twitterToken = ""; // access_token received by authentication user's twitter account String twitterSecret = ""; // access_secret obtained by authentication user's twitter account String tweetId = id; //messageId of the tweet to be retweeted Twitter factory = new TwitterFactory().getInstance(); Twitter twitter = factory; twitter.setOAuthConsumer(consumerKey, consumerSecret); AccessToken accessToken = new AccessToken(twitterToken, twitterSecret); twitter.setOAuthAccessToken(accessToken); twitter.retweetStatus(Long.valueOf(tweetId)); } catch (Exception ex) { System.out.println("Error: " + ex.getMessage()); } }
From source file:twitterplugin.TwitterLoginDialog.java
License:Open Source License
/** * Create Gui//from w w w. j a v a 2s. co m */ private void createGui() { setTitle(mLocalizer.msg("login", "Login")); UiUtilities.registerForClosing(this); PanelBuilder content = new PanelBuilder( new FormLayout("5dlu, pref:grow(0.5), 3dlu, 100dlu, fill:pref:grow(0.5), 5dlu")); CellConstraints cc = new CellConstraints(); final Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(mSettings.getConsumerKey(), mSettings.getConsumerSecret()); try { mRequestToken = twitter.getOAuthRequestToken(); mAuthorizationUrl = mRequestToken.getAuthorizationURL(); } catch (TwitterException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } content.appendRow("3dlu"); content.appendRow("pref"); mLabelBrowser = new JLabel("1. " + mLocalizer.msg("step1", "Open authentication page on Twitter")); content.add(mLabelBrowser, cc.xy(2, content.getRowCount())); mUrlButton = new JButton(mLocalizer.msg("openBrowser", "Open browser")); mUrlButton.setToolTipText(mAuthorizationUrl); content.add(mUrlButton, cc.xy(4, content.getRowCount())); mUrlButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Launch.openURL(mAuthorizationUrl); } }); content.appendRow("3dlu"); content.appendRow("pref"); mLabelPin = new JLabel("2. " + mLocalizer.msg("step2", "Enter PIN from web page")); content.add(mLabelPin, cc.xy(2, content.getRowCount())); mPIN = new JTextField(); content.add(mPIN, cc.xy(4, content.getRowCount())); ButtonBarBuilder builder = new ButtonBarBuilder(); builder.addGlue(); JButton ok = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mReturnValue = JOptionPane.OK_OPTION; AccessToken accessToken = null; try { String pin = mPIN.getText().trim(); if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(mRequestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } try { twitter.verifyCredentials().getId(); mSettings.setAccessToken(accessToken); } catch (TwitterException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } setVisible(false); } }); getRootPane().setDefaultButton(ok); JButton cancel = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL)); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { close(); } }); builder.addGriddedButtons(new JButton[] { ok, cancel }); content.appendRow("fill:pref:grow"); content.appendRow("pref"); content.add(builder.getPanel(), cc.xyw(1, content.getRowCount(), 4)); content.appendRow("5dlu"); content.setBorder(Borders.DIALOG_BORDER); getContentPane().add(content.getPanel()); UiUtilities.setSize(this, Sizes.dialogUnitXAsPixel(200, this), Sizes.dialogUnitYAsPixel(140, this)); }
From source file:TwitterPublisher.Connexions.TwitterInterface.java
/** * Publish the given message on twitter. * @param message//from w w w . j a v a 2s. 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 www.j a v a2 s. c om 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 v a2 s .c om*/ 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; }