1. Programmatically get amount of facebook likes for a specific page
  2. 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.
  3. I already know the link Facebook itself provides to get this amount, which is posted below.
  4. http://past.is/awujl
  5. With www.google.com being the website, whose links are being counted and can of course be changed to whichever page one needs.
  6. 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.
  7. 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.
  8. string result;
  9. string urlToXMLfile, currentURL;
  10. currentURL = Globals.NavigateURL(TabId, "", "CategoryId=" + catId, "MovieId=" + Request.QueryString["MovieId"]);
  11. urlToXMLfile = "https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22";
  12. urlToXMLfile += currentURL;
  13. urlToXMLfile += "%22";
  14. //XDocument xdoc = XDocument.Load(urlToXMLfile);
  15. //string test = xdoc.Descendants(XName.Get("like_count")).First().Value;
  16. XmlDocument doc = new XmlDocument();
  17. doc.Load(urlToXMLfile);
  18. result = doc.FirstChild.NextSibling.InnerText;
  19. return result;