List of usage examples for twitter4j Twitter updateStatus
Status updateStatus(String status) throws TwitterException;
From source file:org.springframework.social.showcase.twitter.TwitterShowcaseController.java
License:Apache License
@RequestMapping(value = "/twitter/tweet", method = RequestMethod.POST) public String postTweet(Principal currentUser, TweetForm tweetForm) { try {/*from w w w . java 2 s. com*/ List<ServiceProviderConnection<Twitter>> connections = twitterProvider .getConnections(currentUser.getName()); for (ServiceProviderConnection<Twitter> connection : connections) { Twitter twitter = connection.getServiceApi(); if (tweetForm.isTweetToAll() || twitter.getScreenName().equals(tweetForm.getScreenName())) { twitter.updateStatus(tweetForm.getMessage()); } } } catch (TwitterException e) { // TODO: Decide how to handle this } return "redirect:/twitter"; }
From source file:org.taverna.server.master.notification.TwitterDispatcher.java
@Override public void dispatch(String messageSubject, String messageContent, String targetParameter) throws Exception { // messageSubject ignored String[] target = targetParameter.split(":", 2); if (target == null || target.length != 2) throw new Exception("missing consumer key or secret"); String who = target[0];// w ww . ja v a 2 s . co m if (!isSendAllowed(who)) return; Twitter twitter = getTwitter(who, target[1]); if (messageContent.length() > MAX_MESSAGE_LENGTH) messageContent = messageContent.substring(0, MAX_MESSAGE_LENGTH - 1) + ELLIPSIS; twitter.updateStatus(messageContent); }
From source file:org.timur.justin.JustInActivity.java
License:Apache License
@Override public boolean onOptionsItemSelected(MenuItem item) { if (showTouchAreaView != null) showTouchAreaView.showButtons(false); switch (item.getItemId()) { case R.id.MENU_NEW_TWEET: if (serviceClientObject != null) { TickerServiceAbstract tickerService = serviceClientObject.getServiceObject(); TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService; if (twitterService != null) { final Twitter twitter = twitterService.getTwitterObject(); if (twitter != null) { final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); final EditText editText = new EditText(context); int maxLength = 140; InputFilter[] FilterArray = new InputFilter[1]; FilterArray[0] = new InputFilter.LengthFilter(maxLength); editText.setFilters(FilterArray); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: String inputText = editText.getText().toString(); try { twitter.updateStatus(inputText); } catch (twitter4j.TwitterException twex) { Log.e(LOGTAG, "FAILED on twitter.updateStatus() " + twex); Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG).show(); }//from www . j a v a 2 s . c o m break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; alertDialogBuilder.setTitle("New tweet"); alertDialogBuilder.setView(editText); alertDialogBuilder.setPositiveButton("Send", dialogClickListener) .setNegativeButton("Abort", dialogClickListener).show(); } } } return true; case R.id.MENU_HELP: GlTickerView.openInBrowser("http://timur.mobi/justin-app/"); return true; case R.id.MENU_AUTO_FORWARD: if (glView != null) { if (glView.autoForward) glView.autoForward = false; else glView.autoForward = true; lastJingleTime = SystemClock.uptimeMillis(); if (Config.LOGD) Log.i(LOGTAG, "onOptionsItemSelected() autoForward=" + glView.autoForward); } return true; case R.id.MENU_TOUCHAREAS: if (showTouchAreaView != null) { if (showTouchAreaViewActiveSince == 0l) { showTouchAreaView.showButtons(true); showTouchAreaViewActiveSince = SystemClock.uptimeMillis(); } else { showTouchAreaView.showButtons(false); showTouchAreaViewActiveSince = 0l; } } return true; case R.id.MENU_PROCESS_MSG: if (Config.LOGD) Log.i(LOGTAG, "onOptionsItemSelected() -> showDialog(DIALOG_USE_MSG)"); showDialog(DIALOG_USE_MSG); return true; case R.id.MENU_MORE: showDialog(DIALOG_MORE); return true; } //return super.onOptionsItemSelected(item); return false; }
From source file:org.timur.justin.JustInActivity.java
License:Apache License
@Override public Dialog onCreateDialog(final int id) { Dialog menuDialog = null;/*from w w w . ja va 2 s. c o m*/ if (id == DIALOG_ABOUT) { if (Config.LOGD) Log.i(LOGTAG, "onCreateDialog id==DIALOG_ABOUT setContentView(R.layout.about_dialog)"); menuDialog = new Dialog(this, R.style.NoTitleDialog); menuDialog.setContentView(R.layout.about_dialog); PackageInfo pinfo; int versionNumber = 0; String versionName = ""; try { pinfo = getPackageManager().getPackageInfo(getPackageName(), 0); versionNumber = pinfo.versionCode; versionName = pinfo.versionName; if (Config.LOGD) Log.i(LOGTAG, "onCreateDialog id==DIALOG_ABOUT manifest versionName=" + versionName); TextView textView = (TextView) menuDialog.findViewById(R.id.aboutVersion); textView.setText((CharSequence) ("v" + versionName), TextView.BufferType.NORMAL); } catch (android.content.pm.PackageManager.NameNotFoundException nnfex) { Log.e(LOGTAG, "onClick btnAbout FAILED on getPackageManager().getPackageInfo(getPackageName(), 0) " + nnfex); } return menuDialog; } final GradientDrawable mBackgroundGradient = new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, new int[] { 0x30606060, 0x30000000 }); if (currentEntryTopic != null) { if (Config.LOGD) Log.i(LOGTAG, "onCreateDialog() id=" + id + " link=" + currentEntryTopic.link); } menuDialog = new Dialog(this, R.style.NoTitleDialog); if (id == DIALOG_USE_MSG) { menuDialog.setContentView(R.layout.open_dialog); menuDialog.findViewById(R.id.buttonLayout).setBackgroundDrawable(mBackgroundGradient); // tweet Button btnTweetReply = (Button) menuDialog.findViewById(R.id.buttonOpenTweetReply); if (btnTweetReply != null) { btnTweetReply.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnTweetReply"); if (currentEntryTopic != null) { if (serviceClientObject != null) { TickerServiceAbstract tickerService = serviceClientObject.getServiceObject(); TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService; if (twitterService != null) { final Twitter twitter = twitterService.getTwitterObject(); if (twitter != null) { final EditText editText = new EditText(context); int maxLength = 140; InputFilter[] FilterArray = new InputFilter[1]; FilterArray[0] = new InputFilter.LengthFilter(maxLength); editText.setFilters(FilterArray); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: String inputText = editText.getText().toString(); try { twitter.updateStatus(inputText); } catch (twitter4j.TwitterException twex) { Log.e(LOGTAG, "FAILED on twitter.updateStatus() " + twex); Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG).show(); } break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.setTitle("Reply tweet"); alertDialogBuilder.setMessage(ripTags(currentEntryTopic.title)); editText.setText( "@" + currentEntryTopic.shortName + " " + ripTags(currentEntryTopic.title), TextView.BufferType.EDITABLE); // todo: should show length of message (or rather: 140 - number of characters) alertDialogBuilder.setView(editText); alertDialogBuilder.setPositiveButton("Send", dialogClickListener) .setNegativeButton("Abort", dialogClickListener).show(); } } } } dismissDialog(id); } }); } // retweet Button btnRetweet = (Button) menuDialog.findViewById(R.id.buttonOpenRetweet); if (btnRetweet != null) { btnRetweet.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnRetweet"); if (currentEntryTopic != null) { if (serviceClientObject != null) { TickerServiceAbstract tickerService = serviceClientObject.getServiceObject(); TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService; if (twitterService != null) { final Twitter twitter = twitterService.getTwitterObject(); if (twitter != null) { // yes/no dialog DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: try { twitter.retweetStatus(currentEntryTopic.id); Toast.makeText(context, "delivered retweet", Toast.LENGTH_SHORT).show(); } catch (twitter4j.TwitterException twex) { Log.e(LOGTAG, "FAILED on twitter.retweetStatus() " + twex); Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG).show(); } break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.setTitle("Retweet"); alertDialogBuilder.setMessage(ripTags(currentEntryTopic.title)); alertDialogBuilder.setPositiveButton("Send", dialogClickListener) .setNegativeButton("Abort", dialogClickListener).show(); } } } } dismissDialog(id); } }); } // mark as Favorit Button btnMarkFavorit = (Button) menuDialog.findViewById(R.id.buttonMarkFavorit); if (btnMarkFavorit != null) { btnMarkFavorit.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnMarkFavorit"); if (currentEntryTopic != null) { if (serviceClientObject != null) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnMarkFavorit get tickerService..."); TickerServiceAbstract tickerService = serviceClientObject.getServiceObject(); TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService; if (twitterService != null) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnMarkFavorit got twitterService"); final Twitter twitter = twitterService.getTwitterObject(); if (twitter != null) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnMarkFavorit got twitterObject"); // yes/no dialog DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: try { twitter.createFavorite(currentEntryTopic.id); } catch (twitter4j.TwitterException twex) { Log.e(LOGTAG, "FAILED on twitter.retweetStatus() " + twex); Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG).show(); } break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); if (Config.LOGD) Log.i(LOGTAG, "onClick btnMarkFavorit got alertDialogBuilder"); alertDialogBuilder.setTitle("Mark as favorit"); alertDialogBuilder.setMessage(ripTags(currentEntryTopic.title)); if (Config.LOGD) Log.i(LOGTAG, "onClick btnMarkFavorit alertDialogBuilder start..."); alertDialogBuilder.setPositiveButton("Favorit", dialogClickListener) .setNegativeButton("Abort", dialogClickListener).show(); if (Config.LOGD) Log.i(LOGTAG, "onClick btnMarkFavorit alertDialogBuilder started"); } } } } dismissDialog(id); } }); } // Browse... Button btnBrowse = (Button) menuDialog.findViewById(R.id.buttonOpenBrowse); if (btnBrowse != null) { btnBrowse.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "btnBrowse currentEntryTopic=" + currentEntryTopic); if (currentEntryTopic != null) { glView.openCurrentMsgInBrowser(currentEntryTopic); } dismissDialog(id); } }); } // Send by Mail Button btnEmail = (Button) menuDialog.findViewById(R.id.buttonOpenEmail); if (btnEmail != null) { btnEmail.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "btnEmail currentEntryTopic=" + currentEntryTopic); if (currentEntryTopic != null && currentEntryTopic.title != null) { Intent sendMailIntent = new Intent(Intent.ACTION_SEND); sendMailIntent.putExtra(Intent.EXTRA_SUBJECT, currentEntryTopic.channelName + ": " + ripTags(currentEntryTopic.title).substring(0, 40) + "..."); sendMailIntent.putExtra(Intent.EXTRA_TEXT, ripTags(currentEntryTopic.title)); sendMailIntent.setType("message/rfc822"); startActivity(sendMailIntent); } dismissDialog(id); } }); } // Send by SMS Button btnSMS = (Button) menuDialog.findViewById(R.id.buttonOpenSMS); if (btnSMS != null) { btnSMS.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "btnSMS currentEntryTopic=" + currentEntryTopic); if (currentEntryTopic != null) { Uri smsUri = Uri.parse("smsto:"); Intent sendSmsIntent = new Intent(Intent.ACTION_SENDTO, smsUri); sendSmsIntent.putExtra("sms_body", currentEntryTopic.channelName + ": " + ripTags(currentEntryTopic.title)); //sendSmsIntent.setType("vnd.android-dir/mms-sms"); try { startActivity(sendSmsIntent); } catch (Exception ex) { String errMsg = ex.getMessage(); Toast.makeText(context, errMsg, Toast.LENGTH_LONG).show(); } } dismissDialog(id); } }); } // // bluetooth // Button btnBluetooth = (Button)menuDialog.findViewById(R.id.buttonOpenBluetooth); // if(btnBluetooth!=null) { // btnBluetooth.setOnClickListener(new View.OnClickListener() { // public void onClick(View view) { // if(currentEntryTopic!=null) { // // todo: must implement // Toast.makeText(context, "bluetooth not yet implemented", Toast.LENGTH_LONG).show(); // } // dismissDialog(id); // } // } // ); // } // close Button btnClose = (Button) menuDialog.findViewById(R.id.buttonClose); if (btnClose != null) { btnClose.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { dismissDialog(id); } }); } } else if (id == DIALOG_MORE) { menuDialog.setContentView(R.layout.more_dialog); menuDialog.findViewById(R.id.buttonLayout).setBackgroundDrawable(mBackgroundGradient); // browse Favorits Button btnBrowseFavorits = (Button) menuDialog.findViewById(R.id.buttonBrowseFavorits); if (btnBrowseFavorits != null) { btnBrowseFavorits.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnBrowseFavorits glView=" + glView); if (glView != null) { if (serviceClientObject != null) { TickerServiceAbstract tickerService = serviceClientObject.getServiceObject(); TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService; if (Config.LOGD) Log.i(LOGTAG, "onClick btnBrowseFavorits twitterService=" + twitterService); if (twitterService != null) { final Twitter twitter = twitterService.getTwitterObject(); if (twitter != null) { try { glView.openInBrowser( "http://twitter.com/" + twitter.getScreenName() + "/favorites"); } catch (twitter4j.TwitterException twex) { Log.e(LOGTAG, "FAILED on twitter.getScreenName() " + twex); Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG).show(); } } } } } dismissDialog(id); } }); } // re-login / clear password Button btnClearPassword = (Button) menuDialog.findViewById(R.id.buttonClearPassword); if (btnClearPassword != null) { btnClearPassword.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword serviceClientObject=" + serviceClientObject); if (serviceClientObject != null) { final TickerServiceAbstract tickerService = serviceClientObject.getServiceObject(); final TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService; if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword twitterService=" + twitterService); if (twitterService != null) { // yes/no dialog DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword MENU_CLEAR_PASSWORD"); twitterService.clearTwitterLogin(); // restart activity if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword restart activity"); Intent intent = getIntent(); overridePendingTransition(0, 0); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); finish(); try { Thread.sleep(1500); } catch (Exception ex2) { } ; if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword finish() done, starting..."); overridePendingTransition(0, 0); startActivity(intent); // on restart, OAuthActivity will be opened break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword got alertDialogBuilder"); alertDialogBuilder.setTitle("Re-Login"); if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword alertDialogBuilder start..."); alertDialogBuilder.setPositiveButton("Re-Login", dialogClickListener) .setNegativeButton("Abort", dialogClickListener).show(); if (Config.LOGD) Log.i(LOGTAG, "onClick btnClearPassword alertDialogBuilder started"); } } dismissDialog(id); } }); } // shutdown all Button btnShutdownAll = (Button) menuDialog.findViewById(R.id.buttonShutdownAll); if (btnShutdownAll != null) { btnShutdownAll.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnShutdownAll serviceClientObject=" + serviceClientObject); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: if (serviceClientObject != null) { TickerServiceAbstract tickerService = serviceClientObject .getServiceObject(); if (tickerService != null) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnShutdownAll tickerService.stopSelf()"); tickerService.stopSelf(); } } if (Config.LOGD) Log.i(LOGTAG, "onClick btnShutdownAll System.exit(0)"); System.exit(0); break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.setTitle("Shutdown all"); alertDialogBuilder.setPositiveButton("Shut down", dialogClickListener) .setNegativeButton("Keep running", dialogClickListener).show(); dismissDialog(id); } }); } // about Button btnAbout = (Button) menuDialog.findViewById(R.id.buttonAbout); if (btnAbout != null) { btnAbout.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnAbout"); showDialog(DIALOG_ABOUT); dismissDialog(id); } }); } // promote Button btnPromote = (Button) menuDialog.findViewById(R.id.buttonPromote); if (btnPromote != null) { btnPromote.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnPromote"); showDialog(DIALOG_PROMOTE); dismissDialog(id); } }); } // close Button btnClose = (Button) menuDialog.findViewById(R.id.buttonClose); if (btnClose != null) { btnClose.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { dismissDialog(id); } }); } } else if (id == DIALOG_PROMOTE) { if (Config.LOGD) Log.i(LOGTAG, "onCreateDialog id==DIALOG_PROMOTE setContentView(R.layout.promote_dialog)"); menuDialog = new Dialog(this, R.style.NoTitleDialog); menuDialog.setContentView(R.layout.promote_dialog); // promote mail Button btnPromoteMail = (Button) menuDialog.findViewById(R.id.buttonPromoteMail); if (btnPromoteMail != null) { btnPromoteMail.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnPromoteMail"); Intent sendMailIntent = new Intent(Intent.ACTION_SEND); sendMailIntent.putExtra(Intent.EXTRA_SUBJECT, "Just in... for Android"); sendMailIntent.putExtra(Intent.EXTRA_TEXT, "Hi \ncheck this out...\n\nJust in... OpenGL Twitter reader free download from Android Market\nhttp://market.android.com/details?id=org.timur.justin\n"); sendMailIntent.setType("message/rfc822"); startActivity(sendMailIntent); dismissDialog(id); } }); } // promote SMS Button btnPromoteSMS = (Button) menuDialog.findViewById(R.id.buttonPromoteSMS); if (btnPromoteSMS != null) { btnPromoteSMS.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnPromoteSMS"); Uri smsUri = Uri.parse("smsto:"); Intent sendSmsIntent = new Intent(Intent.ACTION_SENDTO, smsUri); sendSmsIntent.putExtra("sms_body", "Just in... OpenGL Twitter reader free DL from Android Market http://market.android.com/details?id=org.timur.justin"); //sendSmsIntent.setType("vnd.android-dir/mms-sms"); try { startActivity(sendSmsIntent); } catch (Exception ex) { String errMsg = ex.getMessage(); Toast.makeText(context, errMsg, Toast.LENGTH_LONG).show(); } dismissDialog(id); } }); } // promote tweet Button btnPromoteTweet = (Button) menuDialog.findViewById(R.id.buttonPromoteTweet); if (btnPromoteTweet != null) { btnPromoteTweet.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { if (Config.LOGD) Log.i(LOGTAG, "onClick btnPromoteTweet"); if (serviceClientObject != null) { TickerServiceAbstract tickerService = serviceClientObject.getServiceObject(); TwitterServiceAbstract twitterService = (TwitterServiceAbstract) tickerService; if (twitterService != null) { final Twitter twitter = twitterService.getTwitterObject(); if (twitter != null) { final EditText editText = new EditText(context); int maxLength = 140; InputFilter[] FilterArray = new InputFilter[1]; FilterArray[0] = new InputFilter.LengthFilter(maxLength); editText.setFilters(FilterArray); DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case DialogInterface.BUTTON_POSITIVE: String inputText = editText.getText().toString(); try { twitter.updateStatus(inputText); } catch (twitter4j.TwitterException twex) { Log.e(LOGTAG, "FAILED on twitter.updateStatus() " + twex); Toast.makeText(context, twex.getMessage(), Toast.LENGTH_LONG) .show(); } break; case DialogInterface.BUTTON_NEGATIVE: break; } } }; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); alertDialogBuilder.setTitle("Tweet"); //alertDialogBuilder.setMessage(""); editText.setText( "'Just in...' #OpenGL #Twitter reader free DL from #Android Market http://market.android.com/details?id=org.timur.justin", TextView.BufferType.EDITABLE); // todo: should show length of message (or rather: 140 - number of characters) alertDialogBuilder.setView(editText); alertDialogBuilder.setPositiveButton("Send", dialogClickListener) .setNegativeButton("Abort", dialogClickListener).show(); } } } dismissDialog(id); } }); } } return menuDialog; }
From source file:org.twitter.oauth.java
public static void main(String args[]) throws Exception { // The factory instance is re-useable and thread safe. Twitter twitter = TwitterFactory.getSingleton(); twitter.setOAuthConsumer("SjLUa1Pwrs81nIAGiR4f1l4I7", "ISAXBmzqzYLKWQXAaOe09j34APvVOyxahHghLBSvvR0Psnhozl"); RequestToken requestToken = twitter.getOAuthRequestToken(); AccessToken accessToken = null;/*from w w w. jav a 2 s .c om*/ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (null == accessToken) { System.out.println("Open the following URL and grant access to your account:"); System.out.println(requestToken.getAuthorizationURL()); System.out.print("Enter the PIN(if aviailable) or just hit enter.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } //persist to the accessToken for future reference. storeAccessToken((int) twitter.verifyCredentials().getId(), accessToken); Status status = twitter.updateStatus(args[0]); System.out.println("Successfully updated the status to [" + status.getText() + "]."); System.exit(0); }
From source file:org.wso2.carbon.connector.twitter.TwitterUpdateStatus.java
License:Open Source License
public void connect(MessageContext messageContext) throws ConnectException { try {/*w w w . ja va 2 s . c om*/ String statusStr = TwitterUtils.lookupTemplateParamater(messageContext, STATUS); if (statusStr == null || "".equals(statusStr.trim())) { return; } Twitter twitter = new TwitterClientLoader(messageContext).loadApiClient(); Status status = twitter.updateStatus(statusStr); TwitterUtils.storeResponseStatus(messageContext, status); } catch (TwitterException te) { log.error("Failed to show status: " + te.getMessage(), te); TwitterUtils.storeErrorResponseStatus(messageContext, te); } }
From source file:org.yawlfoundation.yawl.twitterService.TwitterService.java
License:Open Source License
private String updateStatus(String msg) { String result;//from ww w . j ava 2s .c o m Twitter twitter = new TwitterFactory().getInstance(); try { twitter.updateStatus(msg); result = "Status successfully posted to Twitter"; } catch (TwitterException te) { result = te.getMessage(); } return result; }
From source file:Origin.Tweet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, TwitterException { response.setContentType("text/html;charset=UTF-8"); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true);//w w w. ja v a 2 s.c o m cb.setOAuthConsumerKey(CONSUMER_KEY); cb.setOAuthConsumerSecret(CONSUMER_SECRET); cb.setOAuthAccessToken(ACCESS_TOKEN); cb.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET); try { Twitter twitter = new TwitterFactory(cb.build()).getInstance(); User user = twitter.verifyCredentials(); HttpSession session = request.getSession(); request.setCharacterEncoding("UTF-8"); //String tweet = encode(request.getParameter("tweet")); String tweet = request.getParameter("tweet"); Status status = twitter.updateStatus(tweet); session.setAttribute("tweet", tweet); request.getRequestDispatcher("/tweet.jsp").forward(request, response); } catch (TwitterException e1) { e1.printStackTrace(); } }
From source file:se.aceone.housenews.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * //from www. j a va 2s . com * @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 .j a v a 2s.c om*/ * * @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); }