How to query Facebook comments plugin comments information using C#?

放肆的年华 提交于 2020-01-06 16:00:16

问题


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:

  1. #configurator bookmark in the url was wrong (it must be removed)

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!