2013-05-17 25 views

回答

2

試試這個Facebook的圖形API

https://graph.facebook.com/me/friends?limit=1 

    Bundle params = new Bundle(); 
    params.putString("limit", "1"); 
    Request tagRequest = new Request(Session.getActiveSession(), me/friends, params, HttpMethod.GET, new Request.Callback() { 

    @Override 
    public void onCompleted(Response response) { 
     //here you can get your friends in json data. and also "paging" with "next" tag. 
    GraphObject graphObject = response.getGraphObject(); 
    JSONObject jsonObject = graphObject.getInnerJSONObject(); 
     String next = jsonObject.getJSONObject("paging").getString("next"); 
} 
//for next friend 
// before using next remove the graph api path from it. i.e "https://graph.facebook.com/" 
    Request.executeGraphPathRequestAsync(Session.getActiveSession(), next, new Request.Callback() { 

    @Override 
    public void onCompleted(Response response) {} 
+0

雖然此鏈接可以回答這個問題後,它是更好地執行這一請求在這裏包括答案的基本部分,並提供參考鏈接。如果鏈接頁面更改,則僅鏈接答案可能會失效。 – David

+0

facebook圖形API給「分頁」作爲標籤。例如「分頁」:{ 「下一頁」:「https://graph.facebook.com/583979919/friends?limit=5000&offset=5000&__after_id=100005879198439」},在這裏你可以設置限制,你可以通過點擊上述要求。不要忘記從請求中刪除「https://graph.facebook.com」,因爲facebook sdk將這個url本身粘貼爲圖形api路徑。我正在編輯我的答案以獲得更多細節。 –

+0

要求更改,所以我還沒有試過這個解決方案。謝謝你的幫助。 – user1767260

3

來實現分頁的最佳方式: 當你得到第一個響應,檢索下一個頁面請求的對象形成Response對象。然後,當你想獲得下一個頁面數據

Response response = yourFirstRequest.executeAndWait(); //getRequestForPagedResults() returns null if there is no more paging, you can get previous page request with parameter PagingDirection.PREVIOUS Request nextPageRequest = response.getRequestForPagedResults(PagingDirection.NEXT);

//當你想下一個頁面信息

nextPageRequest.executeAndWait();