Reputation: 203
I need to either convert my facebook Response to a JSON Object or find another way to use the response in my code.
I've successfully printed my facebook api Response to the log using this:
Log.d("Friend Response in DIB: ", FriendResponse.toString());
Which gives me this:
06-09 14:02:33.706: D/Friend Response in DIB:(12421): {Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[{"id":"1402927803328937","name":"Open Graph Test User"},{"id":"1402874766667901","name":"Jane Dickson"}],"paging":{"next":"https:\/\/graph.facebook.com\/v2.0\/277976949048048\/friends?format=json&access_token=CAAKsYnmrEh0BAGhTzCUOr6r3zMH7tt1mouEXrqsAi2fh1nYK1d1w5iSvBQEjCupMB1SA9f8G9GyAm41Bct0qwnXnHr4H81eHRHQaoEUrm9JhqRk2LNN260mZCNJwiuiqxX24zHrBINqZCcyh9VzsCM7PO2UKGfEJOcxmEhAZCl9v8XrcrBIkaeGNRC7zh7hZASZADRMTACaRUZApjkjyAuFxSWflkqMldfISgz4Lvi2gZDZD&limit=5000&offset=5000&__after_id=enc_Aey9afbBKXSo8gtNoFOb5eEu4paCRUYRSWIG0v3nSeCgpCIWIj7O-gHnmemCVpr7hQgH--aTwM6-lZA6MyqEfF6H"}}}, error: null, isFromCache:false}
This information is correct, and now I need to put the id and name of each returned user into it's own list item in a list view.
I have a code which does this already, except it gets the information from a url using makeHttpRequest.
How do I convert my facebook Response type into a type that will work with this code instead of the makeHttpRequest? :
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_videos, "POST", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
Log.d("Friend Response in DIB: ", FriendResponse.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_ID);
String name = c.getString(TAG_NAME);
etc...
All help much appreciated!
Upvotes: 0
Views: 1048
Reputation: 989
Look at the official Facebook docs here.
If you do an asynchronous (Request.executeAsync()
)request, you'll use a Request.Callback
with an onCompleted(Response response)
method. If you do a request in series (be sure you're not on the main thread), the Response
will be the value returned by the Request.executeAndWait()
method.
From the Response
object, you can call response.getGraphObject().getInnerJsonObject()
. Use the Graph Explorer tool to get a better idea of the structure of the JSON you get from the API call.
Upvotes: 1