Shvet

Untitled

Dec 29th, 2015
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. private void getlikecommentsofpost(final ViewHolder holder, String page_post_id) {
  2. GraphRequest request = GraphRequest.newGraphPathRequest(
  3. accessToken,
  4. "/" + page_post_id,
  5. new GraphRequest.Callback() {
  6. @Override
  7. public void onCompleted(GraphResponse response) {
  8. Log.e("Response", response.getJSONObject() + "");
  9. JSONObject jsonObject = response.getJSONObject();
  10.  
  11. try {
  12. JSONObject likes = jsonObject.getJSONObject("likes");
  13. JSONArray data = likes.getJSONArray("data");
  14. int page_post_likes = data.length();
  15. if (page_post_likes == 0) {
  16. holder.page_post_like_count_text_view.setText("0 Likes");
  17. } else {
  18. holder.page_post_like_count_text_view.setText(page_post_likes + " Likes");
  19. }
  20. try {
  21. for (int i = 0; i < data.length(); i++) {
  22. JSONObject object = data.getJSONObject(i);
  23. String page_post_liked_user_id = object.getString("id");
  24. }
  25. } catch (JSONException e) {
  26. Log.e("JSONException", e.toString());
  27. }
  28.  
  29. } catch (JSONException e) {
  30. Log.e("JSONException", e.toString());
  31. holder.page_post_like_count_text_view.setText("0 Likes");
  32. }
  33. try {
  34.  
  35. JSONObject comments = jsonObject.getJSONObject("comments");
  36. JSONArray data = comments.getJSONArray("data");
  37.  
  38. int comment_count = data.length();
  39.  
  40. if (comment_count == 0) {
  41. holder.page_post_comment_count_text_view.setText("0 Comments");
  42. } else {
  43. holder.page_post_comment_count_text_view.setText(comment_count + " Comments");
  44. }
  45.  
  46. try {
  47. for (int i = 0; i < data.length(); i++) {
  48. JSONObject object = data.getJSONObject(i);
  49. String message = object.getString("message");
  50. String created_time = object.getString("created_time");
  51. String commented_id = object.getString("id");
  52. JSONObject comment_from = object.getJSONObject("from");
  53. String comment_user_name = comment_from.getString("name");
  54. String comment_userid = comment_from.getString("id");
  55. }
  56. } catch (JSONException e) {
  57. Log.e("JSONException", e.toString());
  58. }
  59.  
  60. } catch (JSONException e) {
  61. Log.e("JSONException", e.toString());
  62. holder.page_post_comment_count_text_view.setText("0 Comments");
  63. }
  64.  
  65. try {
  66. JSONObject share = jsonObject.getJSONObject("shares");
  67. int page_post_share_count = share.getInt("count");
  68. if (page_post_share_count == 0) {
  69. holder.page_post_share_count_text_view.setText("0 Shares");
  70. } else {
  71. holder.page_post_share_count_text_view.setText(page_post_share_count + " Shares");
  72. }
  73. } catch (JSONException e) {
  74. Log.e("JSONException", e.toString());
  75. holder.page_post_share_count_text_view.setText("0 Shares");
  76. }
  77. }
  78. });
  79.  
  80. Bundle parameters = new Bundle();
  81. parameters.putString("fields", "likes.summary(true),comments.summary(true),shares");
  82. request.setParameters(parameters);
  83. request.executeAsync();
  84. }
Add Comment
Please, Sign In to add comment