I get mixed results from the following Twitter4J code. Sometimes both parts of the program work (getting the user's last tweet, and posting a new tweet) but most often only one or neither of these parts work. I strongly suspect that it has nothing to do with the Twitter4J API, but that I'm using OAuth in a sloppy way. (P.S. I realize that I'm being VERY sloppy by hard-coding credentials in my code, but I just want to get this thing working before I worry about observing any security conventions.) Thanks.
package twitter4j.examples.user; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; import twitter4j.User; import twitter4j.conf.ConfigurationBuilder; public final class ShowUser { final private static String OAUTH_CONSUMER_KEY= "0m1****************qod0dg"; final private static String OAUTH_CONSUMER_SECRET = "Tudh37Ws********************S1LnnjA"; final private static String OAUTH_ACCESS_TOKEN = "13845***************************FibS5aXFByGRQ8Wr4"; final private static String OAUTH_ACCESS_TOKEN_SECRET = "G2XH***************************JjYcGvQCM"; public static void main(String[] args) { Twitter twitter = null; if (args.length < 1) { System.out .println("Usage: java twitter4j.examples.user.ShowUser [screen name]"); System.exit(-1); } ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true) .setOAuthConsumerKey(OAUTH_CONSUMER_KEY) .setOAuthConsumerSecret(OAUTH_CONSUMER_SECRET) .setOAuthAccessToken( OAUTH_ACCESS_TOKEN) .setOAuthAccessTokenSecret(OAUTH_ACCESS_TOKEN_SECRET); TwitterFactory tf = new TwitterFactory(cb.build()); twitter = tf.getInstance(); try { System.out.println(args[0]); User user = twitter.showUser(args[0]); if (user == null) System.out.println("User is null"); if (user.getStatus() != null) { System.out.println("@" + user.getScreenName()); System.out.println(user.getStatus().getText()); System.out.println("@" + user.getScreenName() + " - " + user.getStatus().getText()); } else { // the user is protected System.out.println("@" + user.getScreenName()); } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to delete status: " + te.getMessage()); } try { twitter.updateStatus("Third successful tweet in a row (from the desktop app)!"); } catch (TwitterException e) { System.err.println("Error occurred while updating the status!"); } } } -- You received this message because you are subscribed to the Google Groups "OAuth" group. To unsubscribe from this group and stop receiving emails from it, send an email to oauth+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.