2017-02-15 130 views
0

我試圖獲取從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" 
} 

問:我怎樣才能獲取實際的評論內容?

+0

https://developers.facebook.com/docs/plugins/faqs#faq_1603507626630008 – CBroe

回答

0

感謝CBroe我已成功地正確地構建請求,並在實現抓取評論信息的另一個步驟:

在URL
  1. #configurator書籤是錯誤的(它必須被移除)

  2. 正確的代碼,以獲取數據

    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#代碼中失敗。但是,這是另一個問題的另一個問題。