List of usage examples for twitter4j TwitterFactory TwitterFactory
public TwitterFactory()
From source file:com.hyperkode.friendshare.activities.TwitterMapViewActivity.java
License:Open Source License
private void setupTwitter() { mSettings = getSharedPreferences(PREFS_NAME, 0); accessToken = mSettings.getString("twitter_access_token", null); accessTokenSecret = mSettings.getString("twitter_access_token_secret", null); // Get Access Token and persist it AccessToken at = new AccessToken(accessToken, accessTokenSecret); // initialize Twitter4J twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(getString(R.string.TWITTER_CONSUMER_KEY), getString(R.string.TWITTER_CONSUMER_SECRET)); twitter.setOAuthAccessToken(at);/* w w w . j a v a2 s . c om*/ }
From source file:com.hyperkode.friendshare.fragment.LoginFragment.java
License:Open Source License
private void authTwitter() { if (titleProgressBar != null) titleProgressBar.setVisibility(View.VISIBLE); // Twitter mTwitter and RequestToken mRequestToken // are private members of this activity mTwitter = new TwitterFactory().getInstance(); mRequestToken = null;//from ww w .j a v a 2s . c om mTwitter.setOAuthConsumer(getString(R.string.TWITTER_CONSUMER_KEY), getString(R.string.TWITTER_CONSUMER_SECRET)); String callbackURL = getString(R.string.TWITTER_CALLBACK_URL); try { mRequestToken = mTwitter.getOAuthRequestToken(callbackURL); } catch (TwitterException e) { e.printStackTrace(); } TwitterWebViewFragment twbf = TwitterWebViewFragment.newInstance(); Bundle args = new Bundle(); args.putString("URL", mRequestToken.getAuthenticationURL()); twbf.setArguments(args); FragmentManager fragmentManager = LoginFragment.this.getActivity().getSupportFragmentManager(); fragmentManager.putFragment(args, "LoginFragment", LoginFragment.this); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.add(R.id.main_view_containter, twbf); fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); }
From source file:com.hyperkode.friendshare.fragment.TwitterListFragment.java
License:Open Source License
private void setupTwitter() { mSettings = this.getActivity().getSharedPreferences(PREFS_NAME, 0); accessToken = mSettings.getString("twitter_access_token", null); accessTokenSecret = mSettings.getString("twitter_access_token_secret", null); // Get Access Token and persist it AccessToken at = new AccessToken(accessToken, accessTokenSecret); // initialize Twitter4J twitter4j = new TwitterFactory().getInstance(); twitter4j.setOAuthConsumer(getString(R.string.TWITTER_CONSUMER_KEY), getString(R.string.TWITTER_CONSUMER_SECRET)); twitter4j.setOAuthAccessToken(at);/*from ww w . j ava 2 s . c o m*/ }
From source file:com.ikungolf.java.javatwitter.directmessage.DestroyDirectMessage.java
License:Apache License
/** * Usage: java twitter4j.examples.directmessages.DestroyDirectMessage [message id] * * @param args message/*from w w w.ja v a2 s . co m*/ */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.directmessages.DestroyDirectMessage [message id]"); System.exit(-1); } try { Twitter twitter = new TwitterFactory().getInstance(); twitter.destroyDirectMessage(Long.parseLong(args[0])); System.out.println("Successfully deleted message [" + args[0] + "]."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to delete message: " + te.getMessage()); System.exit(-1); } }
From source file:com.ikungolf.java.javatwitter.directmessage.GetDirectMessages.java
License:Apache License
private String getLastestMessage() { Twitter twitter = new TwitterFactory().getInstance(); String msg = new String(); try {//from www . j ava 2 s . co m Paging paging = new Paging(1); List<DirectMessage> messages; messages = twitter.getDirectMessages(paging); System.out.println(messages.size()); DirectMessage dm = messages.get(0); System.out.println("Message: " + dm.getText()); messageId = dm.getId(); if (messageId != tempMsgId) { tempMsgId = messageId; } msg = dm.getText(); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get messages: " + te.getMessage()); System.exit(-1); } return msg; }
From source file:com.ikungolf.java.javatwitter.directmessage.GetSentDirectMessages.java
License:Apache License
/** * Usage: java twitter4j.examples.directmessages.GetSentDirectMessages * * @param args message/* ww w. j a va 2s. c o m*/ */ public static void main(String[] args) { try { Twitter twitter = new TwitterFactory().getInstance(); Paging page = new Paging(1); List<DirectMessage> directMessages; do { directMessages = twitter.getSentDirectMessages(page); for (DirectMessage message : directMessages) { System.out.println("To: @" + message.getRecipientScreenName() + " id:" + message.getId() + " - " + message.getText()); } page.setPage(page.getPage() + 1); } while (directMessages.size() > 0 && page.getPage() < 10); System.out.println("done."); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get sent messages: " + te.getMessage()); System.exit(-1); } }
From source file:com.ikungolf.java.javatwitter.directmessage.ShowDirectMessage.java
License:Apache License
/** * Usage: java twitter4j.examples.directmessage.ShowDirectMessage [message id] * * @param args String[]//from w w w .j av a 2 s . co m */ public static void main(String[] args) { if (args.length < 1) { System.out.println("Usage: java twitter4j.examples.directmessage.ShowDirectMessage [message id]"); System.exit(-1); } Twitter twitter = new TwitterFactory().getInstance(); try { DirectMessage message = twitter.showDirectMessage(Long.parseLong(args[0])); System.out.println("From: @" + message.getSenderScreenName() + " id:" + message.getId() + " - " + message.getText()); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get message: " + te.getMessage()); System.exit(-1); } }
From source file:com.ikungolf.java.javatwitter.GetHomeTimeline.java
License:Apache License
/** * Usage: java twitter4j.examples.timeline.GetHomeTimeline * * @param args String[]/*from w w w .j av a 2s. c om*/ */ public static void main(String[] args) { try { // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); User user = twitter.verifyCredentials(); List<Status> statuses = twitter.getHomeTimeline(); System.out.println("Showing @" + user.getScreenName() + "'s home timeline."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:com.ikungolf.java.javatwitter.GetMentions.java
License:Apache License
/** * Usage: java twitter4j.examples.timeline.GetMentions * * @param args String[]/*from w w w . ja va 2 s . com*/ */ public static void main(String[] args) { // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); try { User user = twitter.verifyCredentials(); List<Status> statuses = twitter.getMentionsTimeline(); System.out.println("Showing @" + user.getScreenName() + "'s mentions."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }
From source file:com.ikungolf.java.javatwitter.GetUserTimeline.java
/** * Usage: java twitter4j.examples.timeline.GetUserTimeline * * @param args String[]//from www.ja v a 2 s . c om */ public static void main(String[] args) { // gets Twitter instance with default credentials Twitter twitter = new TwitterFactory().getInstance(); try { List<Status> statuses; String user; // if (args.length == 1) { // user = args[0]; user = "WebUpd8"; statuses = twitter.getUserTimeline(user); // } else { // user = twitter.verifyCredentials().getScreenName(); // statuses = twitter.getUserTimeline(); // } System.out.println("Showing @" + user + "'s user timeline."); for (Status status : statuses) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get timeline: " + te.getMessage()); System.exit(-1); } }