
Cursor-based pagination is the most efficIEnt method of paging and should always be used where possible – a cursor refers to a random string of characters which mark a specific item in a List of data. Unless this item is deleted,the cursor will always point to the same part of the List,but it will be invalIDated if an item is removed. Therefore,your app shouldn’t store any older cursors or assume that they will still be valID.
When reading an edge that supports cursor pagination,you will see the following JsON response:{ "data": [ ... Endpoint data is here ],"paging": { "cursors": { "after": "MTAxNTExOTQ1MjAwNzI5NDE=","before": "NDMyNzQyODI3OTQw" },"prevIoUs": "https://graph.facebook.com/me/albums?limit=25&before=NDMyNzQyODI3OTQw" "next": "https://graph.facebook.com/me/albums?limit=25&after=MTAxNTExOTQ1MjAwNzI5NDE=" }} 我使用这种格式进行API调用,我如何在一个循环中遍历所有页面
/* make the API call */new GraphRequest( session,"/{user-ID}/statuses",null,httpMethod.GET,new GraphRequest.Callback() { public voID onCompleted(GraphResponse response) { /* handle the result */ } }).executeAsync();解决方法 我想出了一个很好的方法来通过Facebook图形API页面使用光标分页 final String[] afterString = {""}; // will contain the next page cursor final Boolean[] noData = {false}; // stop when there is no after cursor do { Bundle params = new Bundle(); params.putString("after",afterString[0]); new GraphRequest( accesstoken,personID + "/likes",params,new GraphRequest.Callback() { @OverrIDe public voID onCompleted(GraphResponse graphResponse) { JsONObject JsonObject = graphResponse.getJsONObject(); try { JsONArray JsonArray = JsonObject.getJsONArray("data"); // your code if(!JsonObject.isNull("paging")) { JsONObject paging = JsonObject.getJsONObject("paging"); JsONObject cursors = paging.getJsONObject("cursors"); if (!cursors.isNull("after")) afterString[0] = cursors.getString("after"); else noData[0] = true; } else noData[0] = true; } catch (JsONException e) { e.printstacktrace(); } } } ).executeAnDWait(); } while(!noData[0] == true); 总结 以上是内存溢出为你收集整理的android – 如何使用Facebook Graph Api基于Cursor的分页全部内容,希望文章能够帮你解决android – 如何使用Facebook Graph Api基于Cursor的分页所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)