Click here to Skip to main content
12,699,492 members (32,811 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# Javascript
Hi experts,

I am writing my first Facebook application using C# SDK.

I am getting required access token from Javascript and then fetching facebook data from using C# server side code.

Above code is working perfectly fine for admin of the facebook application (the user who has created the FB application), but any other user is not getting access token using same code.

I hope my question is clear.

JS code to get access token should work for any user.
Any kind of help is appropriated.

Thanks a lot in advance.

~Amol Borkar
Posted 9-Dec-12 21:49pm
Comments 10-Dec-12 4:42am
i think you are missing the call to login() which is required in case of new users.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

YES Ankit...
You are correct.
Actually in order to read any user's data from FB, you should have proper permissions and that user should allow you to do so. Then and then only a user access token will be issued to you.

Following is a tested working code for the same.

    <div id="wrappertop" runat="server" class="wrapper-top">
    <div id="likegate_overlaycontents" runat="server" class="overlay-contents">
        <div id="like-messaging">
            <img class="head" src="images/h1_likegate.png" alt="" /><br />
            <img class="subhead" src="images/subhead_likegate.png" alt="" /><br />
    <form id="form1" runat="server">
    <div id="fb-root">
        <asp:GridView AutoGenerateColumns="false" AllowPaging="true" PageSize="10" ID="GridView1"
            runat="server" OnPageIn dexChanging="GridView1_PageIndexChanging">
                <asp:BoundField DataField="id" HeaderText="ID" />
                <asp:BoundField DataField="name" HeaderText="NAME" />
    <script type="text/javascript">
        // Load the SDK Asynchronously
        (function (d) {
            var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
            if (d.getElementById(id)) { return; }
            js = d.createElement('script'); = id; js.async = true;
            js.src = "//";
            ref.parentNode.insertBefore(js, ref);
        } (document));

        // Init the SDK upon load
        window.fbAsyncInit = function () {
                appId: '144922775656553', // App ID
                //channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
                status: true, // check login status
                cookie: true, // enable cookies to allow the server to access the session
                xfbml: true  // parse XFBML

            // listen for and handle auth.statusChange events
            FB.Event.subscribe('auth.statusChange', function (response) {
                if (response.authResponse) {
                    // user has auth'd your app and is logged into Facebook
                    FB.api('/me', function (me) {
                        var accessToken = response.authResponse.accessToken;
                        document.getElementById("txtToken").value = accessToken;
                        if ( {
                            document.getElementById('auth-displayname').innerHTML =;
                    document.getElementById('auth-loggedout').style.display = 'none';
                    document.getElementById('auth-loggedin').style.display = 'block';
                } else {
                    // user has not auth'd your app, or is not logged into Facebook
                    document.getElementById('auth-loggedout').style.display = 'block';
                    document.getElementById('auth-loggedin').style.display = 'none';
            $("#auth-logoutlink").click(function () { FB.logout(function () { window.location.reload(); }); });
        Facebook Login Authentication
    <div id="auth-status">
        <div id="auth-loggedout">
            <div class="fb-login-button" autologoutlink="true" scope="email,user_checkins">
                Login with Facebook</div>
        <div id="auth-loggedin" style="display: none">
            Hi, <span id="auth-displayname"></span>(<a href="#" id="auth-logoutlink">logout</a>)
    <asp:Button ID="btnMyDetails" runat="server" Text="GetMyDetails" OnClick="btnMyDetails_Click" />
    <asp:Button ID="btnFriendDetails" runat="server" Text="GetFriendsDetails" OnClick="btnFriendDetails_Click" />
    <asp:TextBox ID="txtToken" runat="server" CssClass="BLOCK"></asp:TextBox>

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100