【问题标题】:How to get Number of shares and Likes for a URL using FacebookGraph API如何使用 FacebookGraph API 获取 URL 的分享数和点赞数
【发布时间】:2015-09-21 17:59:11
【问题描述】:
如何使用 Facebook Graph API 获取 URL 的分享数和点赞数?有几篇文章回答了类似的问题,但每篇文章都提供了不同的方法/fb API。
我正在使用 C# SDK,我想我应该使用 Graph API,因为最新的 FB API 不支持 FQL。
This answer 看起来不错,但发帖人说分享的返回值是该 URL 的分享和喜欢的总和,我需要它们。
【问题讨论】:
标签:
c#
facebook
facebook-graph-api
facebook-fql
facebook-c#-sdk
【解决方案1】:
在 facebook 上发布帖子后,您将从 facebook 获得帖子 ID(138885734110127_1484064888656364) 作为回报。使用该帖子 ID,您可以获得喜欢和 cmets 的计数,以及喜欢和 cmets 的人数,以及发表的评论。我不知道股票。
获取点赞和cmets的代码如下:
var fb = new FacebookClient("Your Access token here");
var WallPost = fb.Get("138885734110127_1484064888656364");
JObject jObj = JObject.Parse(WallPost.ToString());
var Comments = jObj.Property("comments");
var Likes = jObj.Property("likes");
你会得到json。希望这可以帮助。 :)
【解决方案2】:
我想我可能有点晚了,但这是我获取 URL 的分享、喜欢和 cmets 的代码,请注意它不需要访问令牌,希望这在某种程度上有所帮助!
string url = "http://www.youtube.com";
string QUrl = "https://graph.facebook.com/?fields=id,share,og_object{engagement{count},likes.summary(true).limit(0),comments.limit(0).summary(true)}&id=" + url;
System.Net.HttpWebRequest Request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(QUrl);
Request.ContentType = "text/json";
Request.Timeout = 10000;
Request.Method = "GET";
string content;
using (WebResponse myResponse = Request.GetResponse())
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8))
{
content = sr.ReadToEnd();
}
};
var json = JObject.Parse(content);
var like_count = json["og_object"]["likes"]["summary"]["total_count"];
Console.WriteLine("Like Count :" + like_count);
var share_count = json["share"]["share_count"];
Console.WriteLine("Share Count :" + share_count);
var comment_count = json["og_object"]["comments"]["summary"]["total_count"];
Console.WriteLine("Comment Count :" + comment_count);