- Programmatically get amount of facebook likes for a specific page
- I'm building a website in ASP.net/C# and currently I want to get the amount of Facebook likes of a specific page (think of a video/article). I need this value programmatically, because I want to sort on it later, but that's a different story.
- I already know the link Facebook itself provides to get this amount, which is posted below.
- http://past.is/awujl
- With www.google.com being the website, whose links are being counted and can of course be changed to whichever page one needs.
- Does anybody know how I can access the xml file, of the URL/XML file posted above? I've done some research, but I can't seem to find an answer that works for me.
- EDIT: I found the answer. I had to navigate through the XML a bit and modify the actual URL used. Working code is posted below.
- string result;
- string urlToXMLfile, currentURL;
- currentURL = Globals.NavigateURL(TabId, "", "CategoryId=" + catId, "MovieId=" + Request.QueryString["MovieId"]);
- urlToXMLfile = "https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22";
- urlToXMLfile += currentURL;
- urlToXMLfile += "%22";
- //XDocument xdoc = XDocument.Load(urlToXMLfile);
- //string test = xdoc.Descendants(XName.Get("like_count")).First().Value;
- XmlDocument doc = new XmlDocument();
- doc.Load(urlToXMLfile);
- result = doc.FirstChild.NextSibling.InnerText;
- return result;
Loading
Replies
Know the answer? Post it — somebody with the same question will find it here.