如何使用C#查询Facebook评论插件评论信息? [英] How to query Facebook comments plugin comments information using C#?
问题描述
我正试图从此页面中获取评论信息(向下滚动到* *注释插件代码生成器*部分)
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");
但是,我只收到这样的JSON结果:
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"
}
问题:如何获取实际评论内容?
推荐答案
感谢 CBroe
我设法正确构造了请求并向获取评论信息迈出了一步:
Thanks to CBroe
I have managed to correctly construct the request and to make another step towards fetching comment information:
-
#configurator
网址中的书签错误(必须将其删除)
#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}");
放入 pageUrl < Chrome中的/ code>会收到注释,但在IE11和C#代码中将失败。但是,这是另一个问题的另一个问题。
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.
这篇关于如何使用C#查询Facebook评论插件评论信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!