/** * Use cursors to fetch upto jtwit.maxResults TODO More controlled paging?? * * @param url API method to call * @param screenName * @param userId * @return twitter-id numbers for friends/followers of screenName or userId Is affected by {@link * #maxResults} */ private List<Number> getUserIDs(String url, String screenName, Long userId) { Long cursor = -1L; List<Number> ids = new ArrayList<Number>(); if (screenName != null && userId != null) throw new IllegalArgumentException( "cannot use both screen_name and user_id when fetching user_ids"); Map<String, String> vars = InternalUtils.asMap("screen_name", screenName, "user_id", userId); while (cursor != 0 && !jtwit.enoughResults(ids)) { vars.put("cursor", String.valueOf(cursor)); String json = http.getPage(url, vars, http.canAuthenticate()); try { // it seems Twitter will occasionally return a raw array JSONArray jarr; if (json.charAt(0) == '[') { jarr = new JSONArray(json); cursor = 0L; } else { JSONObject jobj = new JSONObject(json); jarr = (JSONArray) jobj.get("ids"); cursor = new Long(jobj.getString("next_cursor")); } for (int i = 0; i < jarr.length(); i++) { ids.add(jarr.getLong(i)); } if (jarr.length() == 0) { // No more break; } } catch (JSONException e) { throw new TwitterException.Parsing(json, e); } } return ids; }
/** * @return an array of numeric user ids the authenticating user is blocking. Use {@link * #showById(Collection)} if you want to convert thse into User objects. */ public List<Number> getBlockedIds() { String json = http.getPage(jtwit.TWITTER_URL + "/blocks/ids.json", null, true); try { JSONArray arr = json.startsWith("[") ? new JSONArray(json) : new JSONObject(json).getJSONArray("ids"); List<Number> ids = new ArrayList(arr.length()); for (int i = 0, n = arr.length(); i < n; i++) { ids.add(arr.getLong(i)); } return ids; } catch (JSONException e) { throw new TwitterException.Parsing(json, e); } }