List of usage examples for twitter4j AccountSettings getScreenName
String getScreenName();
From source file:jp.ky.twittersample.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * * @param args message//ww w . j ava2 s .co m */ public static void main(String[] args) { // if (args.length < 1) { // System.out.println("Usage: java twitter4j.examples.tweets.UpdateStatus [text]"); // System.exit(-1); // } String message = "Test5"; try { Twitter twitter = new TwitterFactory().getInstance(); try { // get request token. // this will throw IllegalStateException if access token is already available RequestToken requestToken = twitter.getOAuthRequestToken(); System.out.println("Got request token."); System.out.println("Request token: " + requestToken.getToken()); System.out.println("Request token secret: " + requestToken.getTokenSecret()); AccessToken accessToken = null; 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 available) and hit enter after you granted access.[PIN]:"); String pin = br.readLine(); try { if (pin.length() > 0) { accessToken = twitter.getOAuthAccessToken(requestToken, pin); } else { accessToken = twitter.getOAuthAccessToken(requestToken); } } catch (TwitterException te) { if (401 == te.getStatusCode()) { System.out.println("Unable to get the access token."); } else { te.printStackTrace(); } } } System.out.println("Got access token."); System.out.println("Access token: " + accessToken.getToken()); System.out.println("Access token secret: " + accessToken.getTokenSecret()); } catch (IllegalStateException ie) { // access token is already available, or consumer key/secret is not set. if (!twitter.getAuthorization().isEnabled()) { System.out.println("OAuth consumer key/secret is not set."); System.exit(-1); } } //Status status = twitter.updateStatus(message); //System.out.println("Successfully updated the status to [" + status.getText() + "]."); AccountSettings as = twitter.getAccountSettings(); System.out.println("accountsettings:" + as.getScreenName()); System.exit(0); } 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); } }
From source file:twitter4j.examples.account.GetAccountSettings.java
License:Apache License
/** * Usage: java twitter4j.examples.account.GetAccountSettings * * @param args arguments doesn't take effect with this example *//*from w ww . ja va 2 s .c om*/ public static void main(String[] args) { try { Twitter twitter = new TwitterFactory().getInstance(); AccountSettings settings = twitter.getAccountSettings(); System.out.println("Sleep time enabled: " + settings.isSleepTimeEnabled()); System.out.println("Sleep end time: " + settings.getSleepEndTime()); System.out.println("Sleep start time: " + settings.getSleepStartTime()); System.out.println("Geo enabled: " + settings.isGeoEnabled()); System.out.println("Screen name: " + settings.getScreenName()); System.out.println("Listing trend locations:"); Location[] locations = settings.getTrendLocations(); for (Location location : locations) { System.out.println(" " + location.getName()); } System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get account settings: " + te.getMessage()); System.exit(-1); } }