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:
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.