使用cordova获取facebook用户档案
我想在用户登录facebook时获得名字、姓氏和电子邮件。我的应用程序在科尔多瓦。我正在使用cordova插件进行facebook身份验证这一个“”。我可以使用Facebook登录,但如何从中获取姓名和电子邮件。使用cordova获取facebook用户档案,facebook,cordova,cordova-plugins,Facebook,Cordova,Cordova Plugins,我想在用户登录facebook时获得名字、姓氏和电子邮件。我的应用程序在科尔多瓦。我正在使用cordova插件进行facebook身份验证这一个“”。我可以使用Facebook登录,但如何从中获取姓名和电子邮件。 提前感谢。使用下面的命令添加facebook cordova插件 html代码 <div onclick="fblogin();"><img src="img/facebook.png" /></div> Javascript代码 <s
提前感谢。使用下面的命令添加facebook cordova插件 html代码
<div onclick="fblogin();"><img src="img/facebook.png" /></div>
Javascript代码
<script>
function fblogin(){
facebookConnectPlugin.login( ["public_profile","email"],
function (response) {
if(response.authResponse.userID!=''){
facebookConnectPlugin.api(response.authResponse.userID+"/?fields=id,email,first_name", ["public_profile"],
function (response) {
console.log('SUCCESS:'+response);
alert('first_name : '+response.first_name+',email:'+response.email+',id:'+response.id);
},
function (response) {
console.log('ERROR:'+response);
});
}
},
function (response) {
console.log('ERROR:'+response);
});
}
</script>
函数fblogin(){
facebookConnectPlugin.login([“public_profile”,“email”],
功能(响应){
if(response.authResponse.userID!=''){
facebookConnectPlugin.api(response.authResponse.userID+“/?fields=id,email,first_name“,[“public_profile”],
功能(响应){
console.log('成功:'+响应);
警报('first_name:'+response.first_name+',email:'+response.email+',id:'+response.id);
},
功能(响应){
console.log('错误:'+响应);
});
}
},
功能(响应){
console.log('错误:'+响应);
});
}
使用下面的代码片段尝试此登录功能
var fbLogin = function() {
facebookConnectPlugin.login(["public_profile", "email", "user_birthday", "user_location"],
function(response) {
console.log("Login Response :" + JSON.stringify(response));
//alert("Login Response :" + JSON.stringify(response))
this.authId = response.authResponse.userID;
if (response.status == "connected") {
facebookConnectPlugin.api("/" + response.authResponse.userID, ["public_profile", "email", "user_birthday", "user_location"],
function(result) {
this.email = result.email;
this.firstname = result.first_name;
this.lastname = result.last_name;
this.birthdate = result.birthday;
this.city = result.location.name;
},
function(error) {
alert("Failed: " + error);
});
}
},
function(response) {
alert("Other Response : " + JSON.stringify(response))
});
}
非常感谢kishore。真是太棒了!!谢谢。。jay@Krishnavrinsoft你有带这个密码的电子邮件、名字和姓氏吗?@Krishnavrinsoft请在它运行时向上投票。因为我已经给出了第二个答案,所以谢谢:)。是的,我从这个代码中得到了电子邮件和名字。我怎样才能得到姓氏?@Krishnavrinsoft在这里检查,你将用这个
this.lastname=result.last_name代码>。检查它将为您提供所有必需的信息。
var fbLogin = function() {
facebookConnectPlugin.login(["public_profile", "email", "user_birthday", "user_location"],
function(response) {
console.log("Login Response :" + JSON.stringify(response));
//alert("Login Response :" + JSON.stringify(response))
this.authId = response.authResponse.userID;
if (response.status == "connected") {
facebookConnectPlugin.api("/" + response.authResponse.userID, ["public_profile", "email", "user_birthday", "user_location"],
function(result) {
this.email = result.email;
this.firstname = result.first_name;
this.lastname = result.last_name;
this.birthdate = result.birthday;
this.city = result.location.name;
},
function(error) {
alert("Failed: " + error);
});
}
},
function(response) {
alert("Other Response : " + JSON.stringify(response))
});
}