Skip to content

Instantly share code, notes, and snippets.

@gn-spawn
Last active January 7, 2017 03:04
Show Gist options
  • Save gn-spawn/0a69277b781f73832880e0f323002c5d to your computer and use it in GitHub Desktop.
Save gn-spawn/0a69277b781f73832880e0f323002c5d to your computer and use it in GitHub Desktop.
private ArrayList<String> getTweets(String hashtag, String user_name) {
NodeList nodeList = null;
ArrayList<String> tweets = new ArrayList<String>();
try {
URL url = new URL("https://queryfeed.net/tw?q=%23" + URLEncoder.encode(hashtag, "UTF-8") + "+%40" + user_name + "&title-type=user-name-both&geocode=");
URLConnection urlConnection = url.openConnection();
urlConnection.connect();
InputStream inputStream = urlConnection.getInputStream();
// DOM取得
DocumentViewer documentViewer = new DocumentViewer();
Document document = documentViewer.buildDocument(inputStream, "UTF-8");
nodeList = document.getElementsByTagName("description");
for (int i = 0; i < nodeList.getLength(); i++) {
String value = nodeList.item(i).getFirstChild().getNodeValue();
tweets.add(i, value.replaceAll("<.+?>", ""));
}
} catch (IOException e) {
e.printStackTrace();
}
return tweets;
}
@gn-spawn
Copy link
Author

gn-spawn commented Jan 7, 2017

// main文で使う例

ArrayList tweets = mashup.getTweets("スポーンメモ", "gn_spawn");
for (String tweet : tweets) {
System.out.println(tweet);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment