Get Facebook Likes and Comments on page using Graph API in ASP.Net

Last Reply one year ago By Mudassar

Posted one year ago

I want to check facebook share, like comment in asp and my code is given below.

code for my .aspx file


<html xmlns="">
<title>Get facebook shares, comments, likes count of urls</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
$(document).ready(function() {
$('#btnurl').click(function() {
var url = $('#txturl').val();
document.getElementById('tbDetails').style.display = 'block';
type: "POST",
url: "WebService.asmx/BindDatatable",
data: "{urltxt:'" + url + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
for (var i = 0; i < data.d.length; i++) {
$("#tbDetails").append("<tr><td>" + data.d[i].Url + "</td><td>" + data.d[i].SharedCount + "</td><td>" + data.d[i].LikeCount + "</td><td>" + data.d[i].CommentCount + "</td><td>" + data.d[i].ClickCount + "</td><td>" + data.d[i].TotalCount + "</td></tr>");
error: function(result) {
<form id="form1" runat="server">
<td><b>Enter Url:</b></td>
<td><input type="text" id="txturl" /> </td>
<td><input type="button" id="btnurl" value="Get Url Count" /> </td>
<table id="tbDetails" cellpadding="1" cellspacing="1" style="border:solid 1px #000000; display:none">
<thead style="background-color:#DC5807; color:White; font-weight:bold">
<td>Shared Count</td>
<td>Likes Count</td>
<td>Comments Count</td>
<td>Clicks Count</td>
<td>Total Count</td>

code for my WebService.asmx file


using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Net;
using System.Web.Services;

/// <summary>
/// Summary description for AutoCompleteService
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
public class WebService : System.Web.Services.WebService {
public UrlDetails[] BindDatatable(string urltxt)
List<UrlDetails> details = new List<UrlDetails>();
WebClient web = new WebClient();
string url = string.Format(" url, share_count, like_count, comment_count, total_count, click_count FROM link_stat where url='" + urltxt + "'");
string response = web.DownloadString(url);
DataSet ds = new DataSet();
using (StringReader stringReader = new StringReader(response))
ds=new DataSet();
DataTable dt = ds.Tables["link_stat"];
foreach (DataRow dtrow in dt.Rows)
UrlDetails website = new UrlDetails();
website.Url = dtrow["url"].ToString();
website.LikeCount = dtrow["like_count"].ToString();
website.SharedCount = dtrow["share_count"].ToString();
website.CommentCount = dtrow["comment_count"].ToString();
website.ClickCount = dtrow["click_count"].ToString();
website.TotalCount = dtrow["total_count"].ToString();
return details.ToArray();
public class UrlDetails
public string Url { get; set; }
public string SharedCount { get; set; }
public string LikeCount { get; set; }
public string CommentCount { get; set; }
public string ClickCount { get; set; }
public string TotalCount { get; set; }

code working fine but this code get value from html textbox and work on html button click but i want to get url from asp textbox and want to count on asp button click. Can anyone help me to edit this code? Thanks in advance and sorry for my bad english.

You are viewing reply posted by: Mudassar one year ago.