Surendra Sharma

Surendra Sharma

Search This Blog

Thursday, August 22, 2013

How to show Facebook feeds on ASP.NET webpage


Now a days intergation of SNS - Social Networking Sites links and feeds to web site is common requirement in almost all web application development.

This article helps how to display facebook feeds on webpage in ASP.NET.

Facebook provides API calls to get feeds using TOKEN.

Storing token in web.config, database is good place.

protected void Page_Load(object sender, EventArgs e)
{
FacebookToken.Value=ConfigurationManager.AppSettings["FacebookToken"];
}


Use below ASPX page for displaying Facebook feeds

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Show Facebook Tags</title>

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

    <script type="text/javascript">

        $(document).ready(function() {
            $("#FacebookFeeds").attr("data-href", "http://www.facebook.com/" + $("#FacebookToken").val());
            FacebookFeeds(document, 'script', 'facebook-jssdk');
        });
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
            <h1 align="left">
                Facebook Feeds</h1>
        </div>
        <div>
            <div>
                <div>
                    <div id="fb-root">
                    </div>

                    <script type="text/javascript">
                        function FacebookFeeds(d, s, id) {
                            var js, fjs = d.getElementsByTagName(s)[0];
                            if (d.getElementById(id)) return;
                            js = d.createElement(s); js.id = id;
                            js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
                            fjs.parentNode.insertBefore(js, fjs);
                        }
                     </script>

                    <div id="FacebookFeeds" class="fb-like-box" data-width="400" data-height="600" data-border-color="white"
                        data-show-faces="false" data-stream="true" data-header="false">
                    </div>
                </div>
            </div>
            <!—Code Ends Here//-->
        </div>
    </div>
    <asp:HiddenField ID="FacebookToken" runat="server"></asp:HiddenField>
    </form>
</body>

</html>

Please leave your comments or share this tip if it’s useful for you.

No comments:

Post a Comment