How to parse next page of Facebook (SDK 4.0) Graph response in android? -
i fetching list of friends use android application , show them in listview. response call:
graphrequestasynctask graphrequest = new graphrequest( accesstoken.getcurrentaccesstoken(), "/me/friends", null, httpmethod.get, new graphrequest.callback() { public void oncompleted(graphresponse response) { } } ).executeasync();
is
{ "data": [ { "name": "sanjeev sharma", "id": "10xxxxxxxxxx40" }, { "name": "avninder singh", "id": "1xxxxx30" }, { "name": "saikrishna tipparapu", "id": "17xxxxxx98" }, { "name": "perfekt archer", "id": "100xxxxx29" }, { "name": "shathyan raja", "id": "10xxxxx0" }, { "name": "kenny tran", "id": "10xxxxx36164" }, { "name": "lahaul seth", "id": "100xxxxx161" }, { "name": "bappa dittya", "id": "10xxxxx24" }, { "name": "rahul", "id": "10xxxxx }, { "name": "suruchi ", "id": "7xxxxxxxx11" } ], "paging": { "next": "https://graph.facebook.com/76xxxxxxxx28/friends?limit=25&offset=25&__after_id=enc_adaxxxxx5l8nqeymmrxxxxoywak8bxxhrvpxp03gc1eaavaj7q" }, "summary": { "total_count": 382 } }
now how can parse next page of result in android link next page? next page api call done through graph api or facebook only?
ifaour has right idea of how use pagination next, though think right wanted add recursive way fetch results page after page 1 nice list object, project requesting user photos same idea , syntax likes (note whole thing using execute , wait you'll have run separate thread or block ui thread , make app shut down.
bundle param = new bundle(); param.putstring("fields", "id,picture"); param.putint("limit", 100); //setup general callback each graph request sent, callback launch next request if exists. final graphrequest.callback graphcallback = new graphrequest.callback(){ @override public void oncompleted(graphresponse response) { try { jsonarray rawphotosdata = response.getjsonobject().getjsonarray("data"); for(int j=0; j<rawphotosdata.length();j++){ /*save whatever data want result jsonobject photo = new jsonobject(); photo.put("id", ((jsonobject)rawphotosdata.get(j)).get("id")); photo.put("icon", ((jsonobject)rawphotosdata.get(j)).get("picture")); boolean isunique = true; for(jsonobject item : photos){ if(item.tostring().equals(photo.tostring())){ isunique = false; break; } } if(isunique) photos.add(photo);*/ } //get next batch of results of exists graphrequest nextrequest = response.getrequestforpagedresults(graphresponse.pagingdirection.next); if(nextrequest != null){ nextrequest.setcallback(this); nextrequest.executeandwait(); } } catch (jsonexception e) { e.printstacktrace(); } } };
now need make initial request , set callback you've made in previous step, callback handle dirty work of calling rest of items, give items request.
//send first request, rest should called callback new graphrequest(accesstoken.getcurrentaccesstoken(), "me/photos",param, httpmethod.get, graphcallback).executeandwait();
Comments
Post a Comment