List of usage examples for twitter4j IDs getIDs
long[] getIDs();
From source file:com.javielinux.api.loaders.GetUserFriendshipMembersLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {/*from www.j a v a2 s. c o m*/ GetUserFriendshipMembersResponse response = new GetUserFriendshipMembersResponse(); ArrayList<InfoTweet> result = new ArrayList<InfoTweet>(); ConnectionManager.getInstance().open(getContext()); if (request.getType() == FOLLOWERS) { long cursor = -1; IDs followers_ids_response = ConnectionManager.getInstance().getUserForSearchesTwitter() .getFollowersIDs(request.getUser(), cursor); response.setFriendshipMembersIds(followers_ids_response.getIDs()); } else if (request.getType() == FRIENDS) { long cursor = -1; IDs friends_ids_response = ConnectionManager.getInstance().getUserForSearchesTwitter() .getFriendsIDs(request.getUser(), cursor); response.setFriendshipMembersIds(friends_ids_response.getIDs()); } return response; } catch (TwitterException e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } catch (OutOfMemoryError e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } catch (Exception e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
From source file:com.jeanchampemont.wtfdyum.service.impl.TwitterServiceImpl.java
License:Apache License
@Override public Set<Long> getFollowers(final Long userId, final Optional<Principal> principal) throws WTFDYUMException { Preconditions.checkNotNull(userId);/*from ww w .j a v a2 s .co m*/ final Twitter twitter = principal.isPresent() ? twitter(principal.get()) : twitter(); final Set<Long> result = new HashSet<>(); try { IDs followersIDs = null; long cursor = -1; do { followersIDs = twitter.getFollowersIDs(userId, cursor); if (followersIDs.hasNext()) { cursor = followersIDs.getNextCursor(); checkRateLimitStatus(followersIDs.getRateLimitStatus(), WTFDYUMExceptionType.GET_FOLLOWERS_RATE_LIMIT_EXCEEDED); } final Set<Long> currentFollowers = Arrays.stream(followersIDs.getIDs()).boxed() .collect(Collectors.toCollection(() -> new HashSet<>())); result.addAll(currentFollowers); } while (followersIDs.hasNext()); } catch (final TwitterException e) { log.debug("Error while getFollowers", e); throw new WTFDYUMException(e, WTFDYUMExceptionType.TWITTER_ERROR); } return result; }
From source file:com.klinker.android.twitter.services.TalonPullNotificationService.java
License:Apache License
@Override public void onCreate() { super.onCreate(); if (TalonPullNotificationService.isRunning) { stopSelf();/* www . j a v a 2s. co m*/ return; } TalonPullNotificationService.isRunning = true; settings = AppSettings.getInstance(this); mCache = App.getInstance(this).getBitmapCache(); sharedPreferences = getSharedPreferences("com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); pullUnread = sharedPreferences.getInt("pull_unread", 0); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); Intent stop = new Intent(this, StopPull.class); PendingIntent stopPending = PendingIntent.getService(this, 0, stop, 0); Intent popup = new Intent(this, RedirectToPopup.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); popup.putExtra("from_notification", true); PendingIntent popupPending = PendingIntent.getActivity(this, 0, popup, 0); Intent compose = new Intent(this, WidgetCompose.class); popup.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent composePending = PendingIntent.getActivity(this, 0, compose, 0); String text; int count = 0; if (sharedPreferences.getBoolean("is_logged_in_1", false)) { count++; } if (sharedPreferences.getBoolean("is_logged_in_2", false)) { count++; } boolean multAcc = false; if (count == 2) { multAcc = true; } if (settings.liveStreaming && settings.timelineNot) { text = getResources().getString(R.string.new_tweets_upper) + ": " + pullUnread; } else { text = getResources().getString(R.string.listening_for_mentions) + "..."; } mBuilder = new NotificationCompat.Builder(this).setSmallIcon(android.R.color.transparent) .setContentTitle(getResources().getString(R.string.talon_pull) + (multAcc ? " - @" + settings.myScreenName : "")) .setContentText(text).setOngoing(true) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_icon)); if (getApplicationContext().getResources().getBoolean(R.bool.expNotifications)) { mBuilder.addAction(R.drawable.ic_cancel_dark, getApplicationContext().getResources().getString(R.string.stop), stopPending); mBuilder.addAction(R.drawable.ic_popup, getResources().getString(R.string.popup), popupPending); mBuilder.addAction(R.drawable.ic_send_dark, getResources().getString(R.string.tweet), composePending); } try { mBuilder.setWhen(0); } catch (Exception e) { } mBuilder.setContentIntent(pendingIntent); // priority flag is only available on api level 16 and above if (getResources().getBoolean(R.bool.expNotifications)) { mBuilder.setPriority(Notification.PRIORITY_MIN); } mContext = getApplicationContext(); IntentFilter filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.STOP_PUSH"); registerReceiver(stopPush, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.START_PUSH"); registerReceiver(startPush, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.STOP_PUSH_SERVICE"); registerReceiver(stopService, filter); if (settings.liveStreaming && settings.timelineNot) { filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.UPDATE_NOTIF"); registerReceiver(updateNotification, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.NEW_TWEET"); registerReceiver(updateNotification, filter); filter = new IntentFilter(); filter.addAction("com.klinker.android.twitter.CLEAR_PULL_UNREAD"); registerReceiver(clearPullUnread, filter); } Thread start = new Thread(new Runnable() { @Override public void run() { // get the ids of everyone you follow try { Log.v("getting_ids", "started getting ids, mine: " + settings.myId); Twitter twitter = Utils.getTwitter(mContext, settings); long currCursor = -1; IDs idObject; int rep = 0; do { idObject = twitter.getFriendsIDs(settings.myId, currCursor); long[] lIds = idObject.getIDs(); ids = new ArrayList<Long>(); for (int i = 0; i < lIds.length; i++) { ids.add(lIds[i]); } rep++; } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3); ids.add(settings.myId); idsLoaded = true; startForeground(FOREGROUND_SERVICE_ID, mBuilder.build()); mContext.sendBroadcast(new Intent("com.klinker.android.twitter.START_PUSH")); } catch (Exception e) { e.printStackTrace(); TalonPullNotificationService.isRunning = false; pullUnread = 0; Thread stop = new Thread(new Runnable() { @Override public void run() { TalonPullNotificationService.shuttingDown = true; try { //pushStream.removeListener(userStream); } catch (Exception x) { } try { pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception e) { // it isn't running e.printStackTrace(); // try twice to shut it down i guess try { Thread.sleep(2000); pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception x) { // it isn't running x.printStackTrace(); } } TalonPullNotificationService.shuttingDown = false; } }); stop.setPriority(Thread.MAX_PRIORITY); stop.start(); stopSelf(); } catch (OutOfMemoryError e) { TalonPullNotificationService.isRunning = false; Thread stop = new Thread(new Runnable() { @Override public void run() { TalonPullNotificationService.shuttingDown = true; try { //pushStream.removeListener(userStream); } catch (Exception x) { } try { pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception e) { // it isn't running e.printStackTrace(); // try twice to shut it down i guess try { Thread.sleep(2000); pushStream.cleanUp(); pushStream.shutdown(); Log.v("twitter_stream_push", "stopping push notifications"); } catch (Exception x) { // it isn't running x.printStackTrace(); } } TalonPullNotificationService.shuttingDown = false; } }); stop.setPriority(Thread.MAX_PRIORITY); stop.start(); pullUnread = 0; stopSelf(); } } }); start.setPriority(Thread.MAX_PRIORITY - 1); start.start(); }
From source file:com.klinker.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java
License:Apache License
public void getFollowers(final User user, final AsyncListView listView) { spinner.setVisibility(View.VISIBLE); canRefresh = false;/*from w ww .ja v a 2 s . c o m*/ new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); try { if (followingIds == null && user.getId() == settings.myId) { long currCursor = -1; IDs idObject; int rep = 0; do { // gets 5000 ids at a time idObject = twitter.getFriendsIDs(settings.myId, currCursor); long[] lIds = idObject.getIDs(); followingIds = new ArrayList<Long>(); for (int i = 0; i < lIds.length; i++) { followingIds.add(lIds[i]); } rep++; } while ((currCursor = idObject.getNextCursor()) != 0 && rep < 3); } } catch (Throwable t) { followingIds = null; } PagableResponseList<User> friendsPaging = twitter.getFollowersList(user.getId(), currentFollowers); for (int i = 0; i < friendsPaging.size(); i++) { followers.add(friendsPaging.get(i)); } if (friendsPaging.size() > 17) { hasMore = true; } else { hasMore = false; } currentFollowers = friendsPaging.getNextCursor(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (followersAdapter == null) { if (followingIds == null) { // we will do a normal array adapter followersAdapter = new PeopleArrayAdapter(context, followers); } else { followersAdapter = new FollowersArrayAdapter(context, followers, followingIds); } listView.setAdapter(followersAdapter); } else { followersAdapter.notifyDataSetChanged(); } if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); canRefresh = true; spinner.setVisibility(View.GONE); } }); } catch (Exception e) { e.printStackTrace(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (user != null && user.isProtected()) { Toast.makeText(context, getResources().getString(R.string.protected_account), Toast.LENGTH_SHORT).show(); if (settings.roundContactImages) { ImageUtils.loadSizedCircleImage(context, profilePicture, thisUser.getOriginalProfileImageURL(), mCache, 96); } else { ImageUtils.loadImage(context, profilePicture, user.getOriginalProfileImageURL(), mCache); } String url = user.getProfileBannerURL(); ImageUtils.loadImage(context, background, url, mCache); } else { Toast.makeText(context, getResources().getString(R.string.error_loading_timeline), Toast.LENGTH_SHORT).show(); } spinner.setVisibility(View.GONE); canRefresh = false; hasMore = false; } }); } } }).start(); }
From source file:com.mycompany.omnomtweets.RetweetersOfCandidate.java
/** * Method user IDs of retweeters. Paginates on cursor. * @param tweetId id of the tweet we are getting retweeters of * @param calls number of API calls left * @return List of users that retweeted the given tweet. *//* w w w . j a v a 2 s.c o m*/ public List<String> getRetweeters(String tweetId) { //System.out.println("Getting retweeters of " + tweetId); List<String> retweeters = new ArrayList<>(); IDs currentIDs; try { if (calls > 0) { calls -= 1; currentIDs = twitter.getRetweeterIds(Long.parseLong(tweetId), -1); long[] longIDs = currentIDs.getIDs(); //System.out.println("Got " + longIDs.length + " retweeters"); for (int i = 0; i < longIDs.length; i++) { retweeters.add("" + longIDs[i]); } while (calls > 0 && currentIDs.hasNext()) { calls -= 1; currentIDs = twitter.getRetweeterIds(Long.parseLong(tweetId), currentIDs.getNextCursor()); longIDs = currentIDs.getIDs(); //System.out.println("Adding " + longIDs.length + " retweeters"); for (int i = 0; i < longIDs.length; i++) { retweeters.add("" + longIDs[i]); } } } else { System.out.println("Cut off early"); return retweeters; } } catch (TwitterException ex) { System.out.println("Failed to get rate limit status: " + ex.getMessage()); return retweeters; } return retweeters; }
From source file:com.SocialAccess.TwitterSearch.java
public static void searchWhomUserFollow() { List<String[]> data = CSVutil.readCSV(Constants.CSV_FILE_NAME); String[] people = data.get(0); System.out.print(people[0]);/*from w w w . jav a 2 s . c o m*/ try { Twitter twitter = new TwitterFactory().getInstance(); long cursor = -1; IDs ids; System.out.println("Listing following ids."); do { ids = twitter.getFriendsIDs("derekmizak", cursor); for (long id : ids.getIDs()) { System.out.println(id); } } while ((cursor = ids.getNextCursor()) != 0); System.exit(0); } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to get friends' ids: " + te.getMessage()); System.exit(-1); } }
From source file:de.jetsli.twitter.TwitterSearch.java
License:Apache License
public void getFriendsOrFollowers(String userName, AnyExecutor<User> executor, boolean friends, boolean waitIfNoApiPoints) { long cursor = -1; resetRateLimitCache();// w w w .j a va 2 s . c o m MAIN: while (true) { if (waitIfNoApiPoints) { checkAndWaitIfRateLimited("getFriendsOrFollowers 1"); } ResponseList<User> res = null; IDs ids = null; try { if (friends) ids = twitter.getFriendsIDs(userName, cursor); else ids = twitter.getFollowersIDs(userName, cursor); rateLimit--; } catch (TwitterException ex) { if (waitIfNoApiPoints && checkAndWaitIfRateLimited("getFriendsOrFollowers 2", ex)) { // nothing to do } else logger.warn(ex.getMessage()); break; } if (ids.getIDs().length == 0) break; long[] intids = ids.getIDs(); // split into max 100 batch for (int offset = 0; offset < intids.length; offset += 100) { long[] limitedIds = new long[100]; for (int ii = 0; ii + offset < intids.length && ii < limitedIds.length; ii++) { limitedIds[ii] = intids[ii + offset]; } // retry at max N times for every id bunch for (int trial = 0; trial < 5; trial++) { try { res = twitter.lookupUsers(limitedIds); } catch (TwitterException ex) { if (waitIfNoApiPoints && checkAndWaitIfRateLimited("getFriendsOrFollowers 3 (trial " + trial + ")", ex)) { // nothing to do } else { // now hoping that twitter recovers some seconds later logger.error("(trial " + trial + ") error while lookupUsers: " + getMessage(ex)); myWait(10); } continue; } catch (Exception ex) { logger.error("(trial " + trial + ") error while lookupUsers: " + getMessage(ex)); myWait(5); continue; } rateLimit--; for (User user : res) { // strange that this was necessary for ibood if (user.getScreenName().trim().isEmpty()) continue; if (executor.execute(user) == null) break MAIN; } break; } if (res == null) { logger.error("giving up"); break; } } if (!ids.hasNext()) break; cursor = ids.getNextCursor(); } }
From source file:de.jetwick.tw.TwitterSearch.java
License:Apache License
public void getFriendsOrFollowers(String userName, AnyExecutor<JUser> executor, boolean friends) { long cursor = -1; resetRateLimitCache();//from w w w.jav a 2 s . c om MAIN: while (true) { while (getRateLimitFromCache() < LIMIT) { int reset = getSecondsUntilReset(); if (reset != 0) { logger.info("no api points left while getFriendsOrFollowers! Skipping ..."); return; } resetRateLimitCache(); myWait(0.5f); } ResponseList res = null; IDs ids = null; try { if (friends) ids = twitter.getFriendsIDs(userName, cursor); else ids = twitter.getFollowersIDs(userName, cursor); rateLimit--; } catch (TwitterException ex) { logger.warn(ex.getMessage()); break; } if (ids.getIDs().length == 0) break; long[] intids = ids.getIDs(); // split into max 100 batch for (int offset = 0; offset < intids.length; offset += 100) { long[] limitedIds = new long[100]; for (int ii = 0; ii + offset < intids.length && ii < limitedIds.length; ii++) { limitedIds[ii] = intids[ii + offset]; } // retry at max N times for every id bunch for (int i = 0; i < 5; i++) { try { res = twitter.lookupUsers(limitedIds); rateLimit--; for (Object o : res) { User user = (User) o; // strange that this was necessary for ibood if (user.getScreenName().trim().isEmpty()) continue; JUser jUser = new JUser(user); if (executor.execute(jUser) == null) break MAIN; } break; } catch (Exception ex) { ex.printStackTrace(); myWait(5); continue; } } if (res == null) { logger.error("giving up"); break; } } if (!ids.hasNext()) break; cursor = ids.getNextCursor(); } }
From source file:de.vanita5.twittnuker.loader.support.IDsUsersLoader.java
License:Open Source License
@Override public List<User> getUsers(final Twitter twitter) throws TwitterException { if (twitter == null) return null; final CursorPaging paging = new CursorPaging(getCount()); if (getCursor() > 0) { paging.setCursor(getCursor());//from w ww.j a va 2s.c om } final IDs ids = getIDs(twitter, paging); if (ids == null) return null; setCursorIds(ids); return twitter.lookupUsers(ids.getIDs()); }
From source file:demo.UserFollowers.java
License:Apache License
static List<Long> followers(Twitter twitter, String screenName) { List<Long> m_FollowersList = new ArrayList<Long>(); long cursor = -1; //int count = 0; while (true) { IDs ids = null; try {/*ww w . j a v a2 s . c o m*/ //IDs ids = twitter.getFollowersIDs(user.getId(), cursor); ids = twitter.getFollowersIDs(screenName, cursor); } catch (TwitterException twitterException) { // Rate Limit ????????? // (memo) status code ????????? RateLimitStatus rateLimit = twitterException.getRateLimitStatus(); int secondsUntilReset = rateLimit.getSecondsUntilReset(); System.err.println("please wait for " + secondsUntilReset + " seconds"); System.err.println("Reset Time : " + rateLimit.getResetTimeInSeconds()); //() 120?getSecondsUntilReset() ????????????? // long waitTime = (long)(secondsUntilReset + 120) * 1000; long waitTime = (long) (300 * 1000); // 300 try { Thread.sleep(waitTime); } catch (Exception e) { e.printStackTrace(); } continue; } catch (Exception e) { e.printStackTrace(); } long[] idArray = ids.getIDs(); for (int i = 0; i < idArray.length; i++) { //System.out.println("["+(++count)+"]" + idArray[i]); m_FollowersList.add(new Long(idArray[i])); } if (ids.hasNext()) { cursor = ids.getNextCursor(); } else { break; } } return m_FollowersList; }