问题
I am trying to fetch comment information from this page (scroll down to **Comments Plugin Code Generator* section)
I am using FacebookClient
class from Facebook Nuget package to fetch the data. My code is the following:
string oauthUrl = $"https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={appId}&client_secret={appSecret}";
string accessToken = client.DownloadString(oauthUrl).Split('=')[1];
// this is included as a sanity check that the client can fetch data (correct token, proper calls)
var fbClient = new FacebookClient(accessToken);
var fbData = fbClient.Get("/wikipedia/").ToString();
var info = JsonConvert.DeserializeObject<FacebookPageInfo>(fbData);
fbData = fbClient.Get("/wikipedia/posts").ToString();
var posts = JsonConvert.DeserializeObject<FacebookPostData>(fbData);
// this is the code the actually should fetch comments content
// this is the data-href value retrieved from inspecting rendered page
var pageUrl = HttpUtility.UrlDecode("https://developers.facebook.com/docs/plugins/comments#configurator");
var fbComments = fbClient.Get($"/{pageUrl}/comments");
However, I only receive a JSON result result like this:
{
"og_object": {
"id": "246649445486535",
"description": "The Comments box lets people comment on content on your site using their Facebook profile and shows this activity to their friends in news feed. It also contains built-in moderation tools and special...",
"title": "Comments - Social Plugins - Documentation - Facebook for Developers",
"type": "article",
"updated_time": "2017-02-09T22:53:10+0000"
},
"share": {
"comment_count": 0,
"share_count": 4226
},
"id": "https:\/\/developers.facebook.com\/docs\/plugins\/comments#configurator\/comments"
}
Question: How can I fetch actual comments content?
回答1:
Thanks to CBroe
I have managed to correctly construct the request and to make another step towards fetching comment information:
#configurator
bookmark in the url was wrong (it must be removed)proper code to fetch data
var pageUrl = HttpUtility.UrlDecode("https://developers.facebook.com/docs/plugins/comments"); var fbComments = fbClient.Get($"https://graph.facebook.com/v2.6/?fields=og_object{{comments}}&id={pageUrl}");
Putting pageUrl
in Chrome will get the comments, but it fails in IE11 and within C# code. But, that's another issue for another question.
来源:https://stackoverflow.com/questions/42246150/how-to-query-facebook-comments-plugin-comments-information-using-c