簡體   English   中英

使用Graph API,如何檢索評論的圖像並回復評論?

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

我正在創建一個Android應用程序。該應用程序具有使用Graph API檢索Facebook帖子的功能。

我的問題
我的問題是,收到的JSON缺少以下字段:

  • 注釋所附圖片的網址
  • 回復評論
  • 只能提供喜歡的數量。 沒有反應清單
  • 對於包含多個圖像的帖子, full_picture字段僅包含指向一個圖像的鏈接。 其他圖像的鏈接在哪里?

我使用了/me/posts來獲取帖子。

為什么我無法獲得上述詳細信息?

采取的步驟
我搜索了Stackoverflow,但答案僅提及如何獲取圖像和單個評論的答復(通過使用注釋id),但沒有提及如何將其與從"/me/posts"接收的JSON一起使用。 (所以,這不是重復的!!!!)

我的查詢

  • 為什么我無法獲得上述詳細信息?
  • 如何以捆綁的方式獲取父帖子和帖子反應的所有圖片的評論圖像,回復,URL。(即與"/me/posts"的JSON一起使用,而無需為每個/comment運行/comment請求的方式是什么?

我的密碼

編碼執行圖形查詢

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"
    }
}

好吧,關於“反應列表”,這僅適用於Page所有者(從2018年2月起)。

閱讀Graph API文檔: https : //developers.facebook.com/docs/graph-api/reference/v2.12/post

“對於頁面上的帖子:

任何有效的訪問令牌都可以讀取公共頁面上的帖子,但響應中將不包含用戶信息。 頁面訪問令牌可以讀取該頁面上張貼的所有帖子,或該頁面上張貼的所有帖子,並且響應將包括用戶信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM