List of usage examples for twitter4j Twitter getAccountSettings
AccountSettings getAccountSettings() throws TwitterException;
From source file:com.robertszkutak.androidexamples.twitterexample.AndroidTwitterExample.java
License:Open Source License
public boolean isAuthenticated() { if (token == null || secret == null || token == "" || secret == "") { debug = ""; debugStatus.setText(debug);/* w w w. j a va 2 s .co m*/ return false; } else { AccessToken a = new AccessToken(token, secret); Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET); twitter.setOAuthAccessToken(a); try { twitter.getAccountSettings(); return true; } catch (TwitterException e) { debug += "\n\n" + e.getMessage(); debugStatus.setText(debug); return false; } } }
From source file:jp.ky.twittersample.UpdateStatus.java
License:Apache License
/** * Usage: java twitter4j.examples.tweets.UpdateStatus [text] * * @param args message/* w w w . j a va2 s.c om*/ */ 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:org.socialnetlib.android.SocialNetApi.java
License:Apache License
public boolean isAuthenticated() { Twitter twitter = getAndConfigureApiInstance(); if (twitter == null) { return false; }/*from www . ja va 2 s . com*/ try { twitter.getAccountSettings(); return true; } catch (TwitterException e) { return false; } }
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 www . j ava 2 s. com*/ 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); } }
From source file:uk.ac.susx.tag.method51.webapp.handler.TwitterPinAuthHandler.java
License:Apache License
private void getUserInfo(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException { final Params params = new Params(); params.addValidator("id", new SystemStringValidator(true)); new DoSomethingAfterValidatingMyParams(params, request, response) { @Override// ww w . j ava 2s . co m public void something() throws IOException { final String id = request.getParameter("id"); final Twitter twitter = newTwitterInstance(ApiKeyStore.getKey(id)); try { final AccountSettings as = twitter.getAccountSettings(); final String userScreenName = twitter.getScreenName(); final long userId = twitter.getId(); final User user = twitter.showUser(userId); okHereIsYourJson(response, "name", user.getName(), "description", user.getDescription(), "created", user.getCreatedAt(), "favourites_count", user.getFavouritesCount(), "followers_count", user.getFollowersCount(), "friends_count", user.getFriendsCount(), "profile_image_url", user.getProfileImageURL(), "screen_name", userScreenName, "user_id", userId, "language", as.getLanguage(), "sleep_time_enabled", as.isSleepTimeEnabled(), "sleep_end_time", as.getSleepEndTime(), "sleep_start_time", as.getSleepStartTime(), "timezone", as.getTimeZone(), "trend_locations", as.getTrendLocations(), "always_use_https", as.isAlwaysUseHttps(), "discoverable_by_email", as.isDiscoverableByEmail(), "geo_enabled", as.isGeoEnabled()); } catch (TwitterException e) { LOG.warn("Failed to retrieve users data.", e); error(e.getMessage()); } } }; }