Click here to Skip to main content
13,446,281 members (33,821 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 13 Nov 2010

Integrate FB javascript API to your app to implement FB connect

Rate this:
Please Sign up or sign in to vote.
Simple example to integrate FB javascript API to implement FB Connect application, fast, simple and trusted way to implement FB connect.

I am going to demonstrate how you can use FB Javascript API to implement Facebook connect applications, as the facebook toolkit for .net is extremely unstable. You have to integrate the below code in your app.


1)You need a channel.html file , content of that file is only this tag nothing else not even any standard html tags
<script src=""></script>
2) Top of the page where you are using this code replace your html tag by this tag (required for consistency across browsers)
<html xmlns="" xmlns:fb="">

    <fb:login-button perms="email,user_photos" size="large" length="long">Login with Facebook</fb:login-button>
<div style="display: none;">
    <asp:Button ID="fbRegister" runat="server" Text="Ok"

        onclick="fbRegister_Click"  />
<input id="hidEmail" type="hidden" runat="server" />
<input id="hidFirstName" type="hidden" runat="server" />
<input id="hidLastName" type="hidden" runat="server" />
<input id="hidUID" type="hidden" runat="server" />
<div id="fb-root">
<script src="" type="text/javascript"></script>
<script type="text/javascript">
    FB.init({ appId: 'YOUR_APP_ID', status: true, cookie: true, xfbml: true, channelUrl: "channel.html" });

    FB.Event.subscribe('auth.sessionChange', function(response) {
        if (response.session) {
            FB.api('/me', function(response) {
                $("#<%=hidEmail.ClientID %>").val(;
                $("#<%=hidFirstName.ClientID %>").val(response.first_name);
                $("#<%=hidLastName.ClientID %>").val(response.last_name);
                $("#<%=hidUID.ClientID %>").val(;
                $("#<%= fbRegister.ClientID %>").click();

        } else {
            // The user has logged out, and the cookie has been cleared
function LoginWithFB() {
        $("#<%= fbRegister.ClientID %>").click();

Replace YOUR_APP_ID with your application id that you get during application registration with facebook. You can download sample code from here[^]


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Shahriar Iqbal Chowdhury/Galib
Chief Technology Officer
Bangladesh Bangladesh
I am a Software Engineer and Microsoft .NET technology enthusiast. Professionally I worked on several business domains and on diverse platforms. I love to learn and share new .net technology and my experience I gather in my engineering career. You can find me from here

Personal Site
Personal Blog
FB MS enthusiasts group
About Me

You may also be interested in...


Comments and Discussions

QuestionHow to get the user information back?? Pin
Alesha Mary Milred Fernandes26-Nov-13 23:07
memberAlesha Mary Milred Fernandes26-Nov-13 23:07 
Questionhow to get user info at code behind Pin
anto@almeka16-Mar-12 21:36
memberanto@almeka16-Mar-12 21:36 
GeneralReason for my vote of 5 efficient Pin
Monjurul Habib13-Nov-10 22:12
memberMonjurul Habib13-Nov-10 22:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04-2016 | 2.8.180314.2 | Last Updated 14 Nov 2010
Article Copyright 2010 by Shahriar Iqbal Chowdhury/Galib
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid