如何使用C#查询Facebook评论插件评论信息?
问题描述:
我试图获取从this page注释信息(向下滚动到**评论插件代码生成器*部分)如何使用C#查询Facebook评论插件评论信息?
我使用FacebookClient
类从Facebook Nuget package获取数据。我的代码如下:
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结果导致这样的:
{
"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
我已成功地正确地构建请求,并在实现抓取评论信息的另一个步骤:
#configurator
书签是错误的(它必须被移除)-
正确的代码,以获取数据
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}");
在Chrome中放入pageUrl
会得到评论,但在IE11和C#代码中失败。但是,这是另一个问题的另一个问题。
https://developers.facebook.com/docs/plugins/faqs#faq_1603507626630008 – CBroe