Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@elight
Created June 2, 2009 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elight/122078 to your computer and use it in GitHub Desktop.
Save elight/122078 to your computer and use it in GitHub Desktop.
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