List of usage examples for twitter4j PagableResponseList getNextCursor
@Override
long getNextCursor();
From source file:aic2013.extractor.TwitterDataAccess.java
public void forAllFollowers(TwitterUser twitterUser, Processor<User> processor) throws Exception { long nextCursor = -1; do {/*from w w w.j a v a 2 s . c o m*/ PagableResponseList<User> usersResponse = twitter.getFollowersList(twitterUser.getId(), nextCursor); nextCursor = usersResponse.getNextCursor(); for (User u : usersResponse) { processor.process(u); } } while (nextCursor > 0); }
From source file:com.appspot.bitlyminous.service.impl.TwitterServiceImpl.java
License:Apache License
public void importFriends() { try {/* w ww . ja v a2s.co m*/ Twitter twitter = getTwitterClient(); UserService userService = ServiceFactory.newInstance().createUserService(); boolean exists = true; long cursor = -1; while (exists) { //return 100 follower with status per request PagableResponseList<User> twitterFollowers = twitter.getFollowersStatuses(cursor); for (User user : twitterFollowers) { com.appspot.bitlyminous.entity.User entity = userService .getUserByScreenName(user.getScreenName()); if (entity == null) { entity = new com.appspot.bitlyminous.entity.User(); entity.setScreenName(user.getScreenName()); entity.setLevel(com.appspot.bitlyminous.entity.User.Level.DIRECT_USER); userService.updateUser(entity); twitter.createFriendship(user.getScreenName()); twitter.sendDirectMessage(user.getScreenName(), ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.welcome")); // following fofs will hit the limit soon. // IDs friendsIDs = twitter.getFriendsIDs(user.getId()); // for (int id : friendsIDs.getIDs()) { // twitter.createFriendship(id); // } } else if (entity.getLevel() != com.appspot.bitlyminous.entity.User.Level.DIRECT_USER) { entity.setLevel(com.appspot.bitlyminous.entity.User.Level.DIRECT_USER); userService.updateUser(entity); twitter.createFriendship(user.getScreenName()); twitter.sendDirectMessage(user.getScreenName(), ApplicationResources.getLocalizedString("com.appspot.bitlyminous.message.welcome")); // following fofs will hit the limit soon. // IDs friendsIDs = twitter.getFriendsIDs(user.getId()); // for (int id : friendsIDs.getIDs()) { // twitter.createFriendship(id); // } } } exists = twitterFollowers.hasNext(); cursor = twitterFollowers.getNextCursor(); } } catch (Exception e) { throw new ServiceException(e); } }
From source file:com.daiv.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 ww w . ja v a2s . 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, 100); 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.daiv.android.twitter.ui.profile_viewer.fragments.ProfileFragment.java
License:Apache License
public void getFollowing(final User user, final AsyncListView listView) { spinner.setVisibility(View.VISIBLE); canRefresh = false;// w w w. ja va 2s . c o m new Thread(new Runnable() { @Override public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); PagableResponseList<User> friendsPaging; try { friendsPaging = twitter.getFriendsList(user.getId(), currentFollowing, 100); } catch (OutOfMemoryError e) { return; } for (int i = 0; i < friendsPaging.size(); i++) { following.add(friendsPaging.get(i)); Log.v("friends_list", friendsPaging.get(i).getName()); } if (friendsPaging.size() > 17) { hasMore = true; } else { hasMore = false; } currentFollowing = friendsPaging.getNextCursor(); ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { if (followingAdapter == null) { followingAdapter = new PeopleArrayAdapter(context, following); listView.setAdapter(followingAdapter); } else { followingAdapter.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() { try { 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); } catch (Exception e) { // fragment not attached } canRefresh = false; hasMore = false; } }); } } }).start(); }
From source file:com.dwdesign.tweetings.loader.UserListMembersLoader.java
License:Open Source License
@Override public List<ParcelableUser> getUsers() throws TwitterException { final Twitter twitter = getTwitter(); if (twitter == null) return null; final PagableResponseList<User> users; if (mListId > 0) { if (mUserListId <= 0) { mUserListId = mListId;//from w w w . jav a 2 s . c o m } if (mOwnerId <= 0) { final UserList list = twitter.showUserList(mListId); final User owner = list != null ? list.getUser() : null; mOwnerId = owner != null ? owner.getId() : -1; } users = twitter.getUserListMembers(mListId, mCursor); } else { final UserList list = findUserList(twitter, mUserId, mScreenName, mListName); if (list == null) return null; if (mOwnerId <= 0) { final User owner = list.getUser(); mOwnerId = owner != null ? owner.getId() : -1; } if (list != null && list.getId() > 0) { if (mUserListId <= 0) { mUserListId = list.getId(); } users = twitter.getUserListMembers(list.getId(), mCursor); } else return null; } mNextCursor = users.getNextCursor(); mPrevCursor = users.getPreviousCursor(); final List<ParcelableUser> result = new ArrayList<ParcelableUser>(); final int size = users.size(); for (int i = 0; i < size; i++) { result.add(new ParcelableUser(users.get(i), mAccountId, (mCursor + 1) * 20 + i)); } return result; }
From source file:com.dwdesign.tweetings.loader.UserListSubscribersLoader.java
License:Open Source License
@Override public List<ParcelableUser> getUsers() throws TwitterException { final Twitter twitter = getTwitter(); if (twitter == null) return null; final PagableResponseList<User> users; if (mListId > 0) { users = twitter.getUserListSubscribers(mListId, mCursor); } else {/* w ww . jav a 2 s .co m*/ final UserList list = findUserList(twitter, mUserId, mScreenName, mListName); if (list != null && list.getId() > 0) { users = twitter.getUserListSubscribers(list.getId(), mCursor); } else return null; } mNextCursor = users.getNextCursor(); mPrevCursor = users.getPreviousCursor(); final List<ParcelableUser> result = new ArrayList<ParcelableUser>(); final int size = users.size(); for (int i = 0; i < size; i++) { result.add(new ParcelableUser(users.get(i), mAccountId, (mCursor + 1) * 20 + i)); } return result; }
From source file:com.freshdigitable.udonroad.module.realm.UserSortedCacheRealm.java
License:Apache License
private void updateCursorList(List<User> users) { if (!(users instanceof PagableResponseList)) { return;/*from w w w. jav a 2s . com*/ } final PagableResponseList page = (PagableResponseList) users; lastPageCursor = page.getNextCursor(); }
From source file:com.github.moko256.twitlatte.BaseUsersFragment.java
License:Apache License
private Single<PagableResponseList<User>> getResponseSingle(long cursor) { return Single.create(subscriber -> { try {//from w w w. j av a 2 s. c om PagableResponseList<User> pageableResponseList = getResponseList(cursor); next_cursor = pageableResponseList.getNextCursor(); ArrayList<com.github.moko256.twitlatte.entity.User> users = new ArrayList<>( pageableResponseList.size()); for (User user : pageableResponseList) { users.add(UserConverterKt.convertToCommonUser(user)); } GlobalApplication.userCache.addAll(users); subscriber.onSuccess(pageableResponseList); } catch (TwitterException e) { subscriber.tryOnError(e); } }); }
From source file:com.javielinux.api.loaders.GetUserListLoader.java
License:Apache License
@Override public BaseResponse loadInBackground() { try {//w w w . ja v a 2s. c o m GetUserListResponse response = new GetUserListResponse(); ConnectionManager.getInstance().open(getContext()); switch (request.getUserListType()) { case GetUserListLoader.OWN_LISTS: ResponseList<UserList> userLists; if (request.getUserId() < 0) { userLists = ConnectionManager.getInstance().getUserForSearchesTwitter() .getUserLists(request.getScreenName()); } else { userLists = ConnectionManager.getInstance().getTwitter(request.getUserId()) .getUserLists(request.getScreenName()); } for (UserList userList : userLists) { response.getUserListArrayList().add(userList); } break; case GetUserListLoader.MEMBERSHIP_LIST: PagableResponseList<UserList> userListMemberships; if (request.getUserId() < 0) { userListMemberships = ConnectionManager.getInstance().getUserForSearchesTwitter() .getUserListMemberships(request.getScreenName(), request.getCursor()); } else { userListMemberships = ConnectionManager.getInstance().getTwitter(request.getUserId()) .getUserListMemberships(request.getScreenName(), request.getCursor()); } response.setNextCursor(userListMemberships.getNextCursor()); for (UserList userList : userListMemberships) { response.getUserListArrayList().add(userList); } break; } return response; } catch (Exception e) { e.printStackTrace(); ErrorResponse response = new ErrorResponse(); response.setError(e, e.getMessage()); return response; } }
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;/* w w w . j a 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(); }