简体   繁体   中英

Using Graph API , how to retrieve Images of the comments and replies to the comment?

I am creating an Android App.The App have a feature that retrieve Facebook posts using Graph API.

My Problem
My Problem is , the received JSON lacks the following fields:

  • Url for the images attached with the comments
  • Replies to the comments
  • Only No. of likes available. No Reactions list
  • For posts containing more than one images , full_picture fields contains link to only one image. Where is the link for other images ?

I used the /me/posts to get the posts.

Why I can't get the above details ?

Steps taken
I searched Stackoverflow but The answers only mentioned how to get images and replies for individual commment(by using comment id) , but no reference how to get it alongs with the JSON received from "/me/posts" . (So , this is not a duplicate!!!!)

My Queries

  • Why I can't get the above details ?
  • What is the way to get comment's Images , replies,url for all images of the Parent post and Posts reactions in bundle.(that is along with the JSON of "/me/posts" without running /comment request for each and every comment?

My Code

Code the executes Graph Query

login_button.setReadPermissions(Arrays.asList(
                "public_profile", "email", "user_birthday", "user_friends","user_posts", "user_status")); // Setting permissions

 Bundle params = new Bundle();
               params.putString("fields", "message,created_time,id,full_picture,status_type,source,comments.summary(true),likes.summary(true)");

                params.putString("limit", "100");

  new GraphRequest( loginResult.getAccessToken(), "/me/posts", params, HttpMethod.GET,
                        new GraphRequest.Callback() {
                            public void onCompleted(GraphResponse response)  {
                            /* handle the result */
                            try {
                                EditText postsText = (EditText) findViewById(R.id.postText);
                                String res = response.toString();
                                res = res.replaceAll("\\{Response:\\s*\\w*\\W*\\s*[0-9]*\\W*\\w*:", "");
                                res = res.replaceAll("\\,\\s*error:\\s*null\\W*\\s*","");
                                postsText.setText(res);
                                writeToFile(res,"response");
                            }
                            catch (Exception e) {
                                    e.printStackTrace();
                                }
                                }
                            }

                ).executeAsync();


            }

            @Override
            public void onCancel() {
                txtstatus.setText("Login canceled");
            }

            @Override
            public void onError(FacebookException error) {
                txtstatus.setText("Login failed"+error.getMessage());
            }
        });

JSON

{
    "data": [
        {
            "message": "'A reader lives a thousand lives before he dies. The man who never reads lives only one.'\n- George RR Martin",
            "created_time": "2018-01-28T12:17:54+0000",
            "id": "113326729482474_113029916178822",
            "full_picture": "https://scontent.xx.fbcdn.net/v/t1.0-9/26993527_113029839512163_7617357733573673432_n.jpg?oh=c617cf94e3cdd62320fde60e445f760e&oe=5B22BC72",
            "status_type": "added_photos",
            "likes": {
                "data": [],
                "summary": {
                    "total_count": 0,
                    "can_like": true,
                    "has_liked": true
                }
            },
            "comments": {
                "data": [
                    {
                        "created_time": "2018-01-28T12:23:04+0000",
                        "from": {
                            "name": "Ragesh D Antony",
                            "id": "1845099915531898"
                        },
                        "message": "Such a wonderful Quote ..",
                        "id": "113029916178822_113036856178128"
                    },
                    {
                        "created_time": "2018-01-28T13:59:22+0000",
                        "from": {
                            "name": "Vignesh Lakshmanen",
                            "id": "1558536637578045"
                        },
                        "message": "Superb",
                        "id": "113029916178822_113251916156622"
                    }
                ],
                "paging": {
                    "cursors": {
                        "before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TURNMk9EVTJNVGM0TVRJNE9qRTFNVGN4TkRJeE9EUT0ZD",
                        "after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TWpVeE9URTJNVFUyTmpJeU9qRTFNVGN4TkRjNU5qST0ZD"
                    }
                },
                "summary": {
                    "order": "chronological",
                    "total_count": 2,
                    "can_comment": true
                }
            }
        },
        {
            "message": "\"It's an insane world, but in it there's one sanity, the loyalty of old friends. Friends, we must believe in one another.\" \n\n- Ben Hur",
            "created_time": "2018-01-28T12:14:27+0000",
            "id": "113326729482474_113026646179149",
            "status_type": "mobile_status_update",
            "likes": {
                "data": [
                    {
                        "id": "1845099915531898",
                        "name": "Ragesh D Antony"
                    },
                    {
                        "id": "1558536637578045",
                        "name": "Vignesh Lakshmanen"
                    }
                ],
                "paging": {
                    "cursors": {
                        "before": "MTg0NTA5OTkxNTUzMTg5OAZDZD",
                        "after": "MTU1ODUzNjYzNzU3ODA0NQZDZD"
                    }
                },
                "summary": {
                    "total_count": 2,
                    "can_like": true,
                    "has_liked": false
                }
            },
            "comments": {
                "data": [
                    {
                        "created_time": "2018-01-28T12:24:40+0000",
                        "from": {
                            "name": "Ragesh D Antony",
                            "id": "1845099915531898"
                        },
                        "message": "I like Ben Hur very much",
                        "id": "113026646179149_113040629511084"
                    }
                ],
                "paging": {
                    "cursors": {
                        "before": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TURRd05qSTVOVEV4TURnME9qRTFNVGN4TkRJeU9EQT0ZD",
                        "after": "WTI5dGJXVnVkRjlqZAFhKemIzSTZANVEV6TURRd05qSTVOVEV4TURnME9qRTFNVGN4TkRJeU9EQT0ZD"
                    }
                },
                "summary": {
                    "order": "chronological",
                    "total_count": 1,
                    "can_comment": true
                }
            }
        }
],
"paging": {
        "previous": "https://graph.facebook.com/v2.11/113326729482474/posts?fields=message,created_time,id,full_picture,status_type,source,comments.summary%28true%29,likes.summary%28true%29&limit=100&format=json&since=1517141874&access_token=EAATh9tg5DMIBANl59BIPExJRzwZAhedH6PSsV2ZAO9FvzFiGqAW3HKafH9b7Bb0gSKnQMJktzUhX2DZCB29BezRUfI2HOumZAYp6FFYwOBJA1ZCdaE4ZCNLXB1ctUZBaKwbp8lXlZBwZBLLCG25CnGAckZClJXZA5omRDFtVvnJFTkJpqigUmy22QNGFmF4CgfC6sWEuVin7mAI9WZCkKkNVzSEeDGDoitt7xeVFiHXCetKOVoLZAl3qyfrYj&__paging_token=enc_AdC03uweQZCRZBN6tZCzhAQ50BZCKzx5koYtAZBRUmgY94TKcCrj6owvzXw9lpoL4iBKJUkW1ZAz4MoZAZBBaGSLZAHTHsKuEst7gtKaQrsQoiZBx8sO2QjQZDZD&__previous=1",
        "next": "https://graph.facebook.com/v2.11/113326729482474/posts?fields=message,created_time,id,full_picture,status_type,source,comments.summary%28true%29,likes.summary%28true%29&limit=100&format=json&access_token=EAATh9tg5DMIBANl59BIPExJRzwZAhedH6PSsV2ZAO9FvzFiGqAW3HKafH9b7Bb0gSKnQMJktzUhX2DZCB29BezRUfI2HOumZAYp6FFYwOBJA1ZCdaE4ZCNLXB1ctUZBaKwbp8lXlZBwZBLLCG25CnGAckZClJXZA5omRDFtVvnJFTkJpqigUmy22QNGFmF4CgfC6sWEuVin7mAI9WZCkKkNVzSEeDGDoitt7xeVFiHXCetKOVoLZAl3qyfrYj&until=1517140875&__paging_token=enc_AdC1r6ZBwBybSmO16DuZCEWGDbdqTeiKCbTsa7h6WDenaZBgB40Xbc0flGcwYqiYPFiEf9wEvuBSoEvbfyl25J0JlbyfhKA1ZBufZC5ZAJMqLMg6bAXgZDZD"
    }
}

Well, regarding "reaction list", this is available only for the Page owner (starting from 2018 Febraury).

Read the Graph API docs: https://developers.facebook.com/docs/graph-api/reference/v2.12/post

"For Posts on a Page:

Any valid access token can read posts on a public Page, but responses will not include User information. A Page access token can read all Posts posted to or posted by that Page, and responses will include User information."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM