List of usage examples for twitter4j Twitter getFavorites
ResponseList<Status> getFavorites(long userId) throws TwitterException;
From source file:com.appspot.bitlyminous.standalone.TwitterExample.java
License:Apache License
/** * The main method.//from w ww. ja v a2 s .c o m * * @param args the arguments * * @throws Exception the exception */ public static void main(String[] args) throws Exception { // The factory instance is re-useable and thread safe. Twitter twitter = new TwitterFactory().getInstance(); twitter.setOAuthConsumer("671O1zUicFBCYHHYVp0XA", "cP7WvfAtxXGSaf1Sz0ksZtWGcENosFcRr46WR7a9jU"); RequestToken requestToken = twitter.getOAuthRequestToken(); 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) 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. System.out.println("Screen name:" + accessToken.getScreenName()); System.out.println("Token:" + accessToken.getToken()); System.out.println("Secret:" + accessToken.getTokenSecret()); IDs friendsIDs = twitter.getFriendsIDs("gapinginfinity"); System.out.println(Arrays.toString(friendsIDs.getIDs())); ResponseList<Status> favorites = twitter.getFavorites("gapinginfinity"); System.out.println(favorites.size()); System.exit(0); }
From source file:com.klinker.android.twitter.activities.drawer_activities.FavoritesActivity.java
License:Apache License
public void getFavorites() { if (!hasMore) { return;//w w w . ja v a 2 s .co m } canRefresh = false; final LinearLayout spinner = (LinearLayout) findViewById(R.id.list_progress); new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); final ResponseList<twitter4j.Status> favs = twitter.getFavorites(paging); if (favs.size() < 17) { hasMore = false; } paging.setPage(paging.getPage() + 1); for (twitter4j.Status s : favs) { statuses.add(s); } ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (adapter == null) { if (statuses.size() > 0) { adapter = new TimelineArrayAdapter(context, statuses, TimelineArrayAdapter.FAVORITE); listView.setAdapter(adapter); listView.setVisibility(View.VISIBLE); } else { LinearLayout nothing = (LinearLayout) findViewById(R.id.no_content); nothing.setVisibility(View.VISIBLE); listView.setVisibility(View.GONE); hasMore = false; } } else { adapter.notifyDataSetChanged(); } spinner.setVisibility(View.GONE); canRefresh = true; } }); } catch (Exception e) { e.printStackTrace(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { spinner.setVisibility(View.GONE); canRefresh = false; } }); } catch (OutOfMemoryError e) { e.printStackTrace(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { spinner.setVisibility(View.GONE); canRefresh = false; } }); } } }).start(); }