Skip to content

Instantly share code, notes, and snippets.

@elight
Created Jun 2, 2009
Embed
What would you like to do?
try {
URL url = new URL (urlStr);
String encoding = Base64Coder.encodeString(authInfo);
// Need to work with URLConnection to set request property
URLConnection uc = url.openConnection();
uc.setRequestProperty ("Authorization", "Basic " + encoding);
BufferedReader rd = new BufferedReader(new InputStreamReader(uc.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = rd.readLine()) != null) { sb.append(line); }
JSONTokener tokener = new JSONTokener(sb.toString());
JSONArray array = new JSONArray(tokener);
JSONObject tweetJSON = null;
for(int i=0; i<array.length(); i++) {
tweets.add(new Tweet((JSONObject) array.get(i)));
}
} catch (MalformedURLException e) {
Log.e(APP_NAME, "Invalid URL");
} catch (IOException e) {
Log.e(APP_NAME, "Error reading URL");
} catch(JSONException e) {
Log.e(APP_NAME, e.getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment