Android Facebook GraphResponse get string from an array -
i'm getting confused on i'm reading through. i'm trying specific items array can show them on in view.
i'm using facebook's graphresponse pull ids, names, accesstokens, etc. don't know how use getjsonarray()
or getjsonobject()
or when use either.
i have request:
graphrequest request = graphrequest.newgraphpathrequest( accesstoken, "/me/accounts", new graphrequest.callback() { @override public void oncompleted(graphresponse response) { // insert code here } }); bundle parameters = new bundle(); parameters.putstring("fields", "name,id,access_token"); request.setparameters(parameters); request.executeasync();
which should yield me this:
{ "data": [ { "name": "sample page 1", "id": "1234567890", "access_token": "sample_token" }, { "name": "sample page 2", "id": "2234567890", "access_token": "sample_token" }, { "name": "sample page 3", "id": "3234567890", "access_token": "sample_token" } ], "paging": { "cursors": { "before": "***********", "after": "***********" } } }
now, i'm having problem "your code here" part. i've been experimenting for
loops after making response
array, don't know how each string each page in data.
i've tried playing around this:
jsonarray jsonarray = response.getjsonarray(); for(int i=0; < jsonarray.length(); i++){ //not sure goes in here string of "name" or "access_token }
i'd know how information array inside of graphrequest.
found out how:
graphrequest requestpage = graphrequest.newgraphpathrequest( currentaccesstoken, "/me/accounts", new graphrequest.callback() { @override public void oncompleted(graphresponse response) { jsonarray jsonarray = null; try { jsonarray = response.getjsonobject().getjsonarray("data"); for(int i=0; < jsonarray.length(); i++){ jsonobject page = jsonarray.getjsonobject(i); string pagename = page.getstring("name"); string pagetoken = page.getstring("access_token"); log.d("************", ""+pagename+" "+pagetoken); } } catch (jsonexception e) { e.printstacktrace(); } } }); bundle parameterspages = new bundle(); parameterspages.putstring("fields", "name,access_token"); requestpage.setparameters(parameterspages); requestpage.executeasync();
Comments
Post a Comment