ASP.NET和Facebook登录 [英] ASP.NET and Facebook Login
问题描述
我正在尝试将Facebook登录添加到我的网站。我想出了如何在Facebook上添加应用程序并在我的代码中引用它。当我测试它时,它会拉起Facebook窗口,允许我登录,并将使用Facebook登录图标更改为注销。所以它似乎有点工作,但我无法从登录中获取数据。我查阅了教程,学习如何收集显示名称,性别等。我在javascript中添加了一些警报,看看我能看到什么,但我已经走到了尽头。对OnLogin方法的调用似乎永远不会触发,所以我看不到我的响应对象值。
另外,我使用的是我的实际APP_ID,我只是从下面的示例代码中删除它。 br />
感谢您的任何建议。
< script src =scripts / jquery-1.8.0。 min.jstype =text / javascript>< / script>
< script src =scripts / all.jstype =text / javascript>< /脚本>
< script type =text / javascript>
$(document)。ready(function(){
/ /在加载时初始化SDK
FB.init({
appId:'我的实际ID',//应用ID
channelUrl:' //'+ window.location.hostname +'/ channel',//频道文件的路径
范围:'id,name,gender,user_birthday,email',//这是为了得到用户详细信息从Facebook返回
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true //解析XFBML
});
//监听并处理auth.statusChange事件
FB。 Event.subscribe('auth.statusChange',OnLogin);
});
//此方法将在我们之后调用呃登录到facebook。
函数OnLogin(响应){
alert('Testing');
if(response.authResponse){
FB.api('/ me?fields = id,name,gender,email,birthday',LoadValues);
alert(me.name);
}
}
//此方法会将值加载到标签
函数LoadValues(me){
if(me.name){
document.getElementById('displayname')。innerHTML = me.name;
document.getElementById('FBId')。innerHTML = me.id;
document.getElementById('DisplayEmail')。innerHTML = me.email;
document.getElementById ('性别')。innerHTML = me.gender;
document.getElementById('DOB')。innerHTML = me.birthday;
document.getEleme ntById('auth-loggedin')。style.display ='block';
alert(me.name);
}
}
< / script>
I am trying to add the Facebook login to my site. I figured out how to add the app on Facebook and reference it in my code. When i test this, it pulls up the Facebook window, allows me to login, and changes the, "Login with Facebook" icon to, "Log Out". So it appears to be working somewhat, but I am unable to get the data from the login. I looked up tutorials to learn how to collect the Display Name, Gender, etc. I added a few alerts to the javascript to see what I could see, but I'm at a dead end. The call to the OnLogin method never seems to fire, so i can't see my response object values.
Also, I am using my actual APP_ID, I just removed it from the sample code below.
Thanks for any advice.
<script src="scripts/jquery-1.8.0.min.js" type="text/javascript"></script>
<script src="scripts/all.js" type="text/javascript"></script>
<script type="text/javascript">
$("document").ready(function () {
// Initialize the SDK upon load
FB.init({
appId: 'My Actual ID', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
scope: 'id,name,gender,user_birthday,email', // This to get the user details back from Facebook
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', OnLogin);
});
// This method will be called after the user login into facebook.
function OnLogin(response) {
alert('Testing');
if (response.authResponse) {
FB.api('/me?fields=id,name,gender,email,birthday', LoadValues);
alert(me.name);
}
}
//This method will load the values to the labels
function LoadValues(me) {
if (me.name) {
document.getElementById('displayname').innerHTML = me.name;
document.getElementById('FBId').innerHTML = me.id;
document.getElementById('DisplayEmail').innerHTML = me.email;
document.getElementById('Gender').innerHTML = me.gender;
document.getElementById('DOB').innerHTML = me.birthday;
document.getElementById('auth-loggedin').style.display = 'block';
alert(me.name);
}
}
</script>
推荐答案
(document)。ready(function(){
//加载时初始化SDK
FB.init({
appId:'我的实际ID',// App ID
channelUrl:'//'+ window.location.hostname +'/ channel',//频道文件的路径
范围:'id,name,gender,user_birthday,电子邮件',//这是从Facebook获取用户详细信息
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true //解析XFBML
});
//监听并处理auth.statusChange事件
FB.Event.subscribe('auth.statusChange',OnLogin);
});
//此方法将在用户登录facebook后调用。
函数OnLogin(响应){
alert('Testing');
if(响应。 authResponse){
FB.api('/ me?fields = id,name,gender,email,birthday',LoadValues);
alert(me.name);
}
}
//此方法会将值加载到标签上
函数LoadValues(me){
if(me.name){
document.getElementById('displayname')。innerHTML = me.name;
document.getElementById('FBId')。innerHTML = me.id;
document.getElementById('DisplayEmail')。innerHTML = me.email;
document.getElementById(性别')。innerHTML = me.gender;
document.getElementById('DOB')。innerHTML = me.birthday;
document.getElementById('auth-loggedin' ).style.display ='block';
alert(me.name);
}
}
< / script>
("document").ready(function () {
// Initialize the SDK upon load
FB.init({
appId: 'My Actual ID', // App ID
channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
scope: 'id,name,gender,user_birthday,email', // This to get the user details back from Facebook
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', OnLogin);
});
// This method will be called after the user login into facebook.
function OnLogin(response) {
alert('Testing');
if (response.authResponse) {
FB.api('/me?fields=id,name,gender,email,birthday', LoadValues);
alert(me.name);
}
}
//This method will load the values to the labels
function LoadValues(me) {
if (me.name) {
document.getElementById('displayname').innerHTML = me.name;
document.getElementById('FBId').innerHTML = me.id;
document.getElementById('DisplayEmail').innerHTML = me.email;
document.getElementById('Gender').innerHTML = me.gender;
document.getElementById('DOB').innerHTML = me.birthday;
document.getElementById('auth-loggedin').style.display = 'block';
alert(me.name);
}
}
</script>
这篇关于ASP.NET和Facebook登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!