Skip to content

Instantly share code, notes, and snippets.

@biznickman
Created February 28, 2011 22:59
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 biznickman/848223 to your computer and use it in GitHub Desktop.
Save biznickman/848223 to your computer and use it in GitHub Desktop.
// Processes response from FB API, parses FB Places and transmits place names/IDs to inPulse
private class
IDRequestListener implements RequestListener { 

public void onComplete(String response, Object state) {
 

JSONObject json = null;

JSONArray jArray = null;

try {

// process the response here: executed in background thread

try {

json = Util.parseJson(response);
 

} catch...

 //Finish this catch statement as needed
jArray = json.getJSONArray("data");
 

Log.d(TAG, "jArray length: " + jArray.length());
 

for (int i = Math.min(7, jArray.length()); i >= 0; i--) {
// Iterate through the array

JSONObject eachPlace = jArray.getJSONObject(i);
// The outer JSON object

Log.d(TAG, "eachPlace: " + i + " " + eachPlace.toString());

ids[i] = eachPlace.getString("id");

Log.d(TAG, "place name: " + ids[i]);

int trimmed = Math.min(16, eachPlace.getString("name").length());

places[i] = eachPlace.getString("name").substring(0, trimmed);
// The place's name

Log.d(TAG, "place name: " + places[i]);


// Send each place name + ID to inPulse

byte[] send = pulseprotocol.encodeNotification(0, places[i], Integer.toString(i));

mChatService.write(send);

}
} catch ... //Handle errors as needed
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment