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.
<body>
<div id="wrappertop" runat="server" class="wrapper-top">
</div>
<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 />
</div>
</div>
<form id="form1" runat="server">
<div id="fb-root">
</div>
<div>
<asp:GridView AutoGenerateColumns="false" AllowPaging="true" PageSize="10" ID="GridView1"
runat="server" OnPageIn dexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField DataField="id" HeaderText="ID" />
<asp:BoundField DataField="name" HeaderText="NAME" />
</Columns>
</asp:GridView>
</div>
<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'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
} (document));
// Init the SDK upon load
window.fbAsyncInit = function () {
FB.init({
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;
//alert(accessToken);
document.getElementById("txtToken").value = accessToken;
if (me.name) {
document.getElementById('auth-displayname').innerHTML = me.name;
}
})
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(); }); });
}
</script>
<h1>
Facebook Login Authentication
</h1>
<div id="auth-status">
<div id="auth-loggedout">
<div class="fb-login-button" autologoutlink="true" scope="email,user_checkins">
Login with Facebook</div>
</div>
<div id="auth-loggedin" style="display: none">
Hi, <span id="auth-displayname"></span>(<a href="#" id="auth-logoutlink">logout</a>)
</div>
</div>
<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>
</form>
</body>