JSONException Twitter client

39 views
Skip to first unread message

Roger Rubens

unread,
Jul 5, 2015, 11:08:59 AM7/5/15
to collect...@googlegroups.com

I have an algorithm that performs a search the old tweets on twitter. The application functioned normally for a while, but then began to launch a JSONException.

Here is the code:

public static List<Tweet> getTweets(String username, String since, String until, String querySearch) {
List<Tweet> results = new ArrayList<Tweet>();
try {
String refreshCursor = null;
while (true) {
JSONObject json = new JSONObject(getURLResponse(username, since, until, querySearch, refreshCursor));
EXCEPTION HERE!  --> refreshCursor = json.getString("scroll_cursor");
System.out.println("while");
Document doc = Jsoup.parse((String) json.get("items_html"));
Elements tweets = doc.select("div.js-stream-tweet");
if (tweets.size() == 0) {
break;
}
for (Element tweet : tweets) {
String usernameTweet = tweet.select("span.username.js-action-profile-name b").text();
String txt = tweet.select("p.js-tweet-text").text().replaceAll("[^\\u0000-\\uFFFF]", "");
int retweets = Integer.valueOf(tweet.select("span.ProfileTweet-action--retweet span.ProfileTweet-actionCount").attr("data-tweet-stat-count").replaceAll(",", ""));
int favorites = Integer.valueOf(tweet.select("span.ProfileTweet-action--favorite span.ProfileTweet-actionCount").attr("data-tweet-stat-count").replaceAll(",", ""));
long dateMs = Long.valueOf(tweet.select("small.time span.js-short-timestamp").attr("data-time-ms"));
Date date = new Date(dateMs);
Tweet t = new Tweet(usernameTweet, txt, date, retweets, favorites);
results.add(t);
}
}
} catch (Exception e) {
System.out.println("Error!");
}
return results;
}


The JSONObject json variable has content. I do not know why the exception.

Message has been deleted

adi chris

unread,
Aug 14, 2015, 7:05:51 PM8/14/15
to Collection+JSON
Hi,
Have you fixed this issue?
Reply all
Reply to author
Forward
0 new messages