Sha*_*gie 4 oauth cordova ionic-framework cordova-plugins ngcordova
我已经安装了cordova inapp浏览器插件来添加社交facebook登录.事情是,在我的应用程序中,我只允许通过Facebook登录而不注册.在我的webapp上,如果该用户已经注册,则只有他/她可以访问移动应用程序.所以要从移动应用程序进行登录,回调后是否可以接收用户在facebook按钮点击打开的inapp浏览器中提供的电子邮件ID?如果我重新发送电子邮件ID,我可以交叉验证他/她在数据库中的存在吗?有可能吗?
我的代码是这样的:
$scope.getDeviceInfo = function() {
$cordovaOauth.facebook("777846192309223", ["email"]).then(function(result) {
alert('success login:'+JSON.stringify(result));
}, function(error) {
alert('error: '+error);
});
}
Run Code Online (Sandbox Code Playgroud)
在上面的email参数中,我想在成功登录时从facebook获取用户数据.但我得到的access_token是大约50位数字和另一个参数expires_in,时间戳为7位数.我没有收到电子邮件.怎么做到的?
$scope.getDeviceInfo = function() {
$cordovaOauth.facebook("777846192309223", ["email"]).then(function(result) {
alert('success login:'+JSON.stringify(result));
$localStorage.accessToken = result.access_token;
if($localStorage.hasOwnProperty("accessToken") === true) {
$http.get("https://graph.facebook.com/v2.2/me", { params: { access_token: $localStorage.accessToken, fields: "id,name,gender,location,website,picture,relationship_status",email format: "json" }}).then(function(result) {
$scope.profileData = result.data;
}, function(error) {
alert("There was a problem getting your profile. Check the logs for details.");
console.log(error);
});
} else {
alert("Not signed in");
$location.path("/login");
}
}, function(error) {
alert('error: '+error);
});
}Run Code Online (Sandbox Code Playgroud)
将访问令牌存储到localstorage.并使用facebook graph api获取用户电子邮件ID等
| 归档时间: |
|
| 查看次数: |
1229 次 |
| 最近记录: |