我正在使用angularjs并使用https://github.com/Ciul/angular-facebook模块在facebook上创建登录。但现在我无法在登录后获取用户数据:
我的控制器是:
$scope.facebookLogin = function () {
var promise = authenticationServices.fbLogin();
promise.then(
function(data){
console.log(data);
},
function(error){
utilityServices.showToast('error', 'Unable to connect with facebook');
});
};
我的服务是:
this.fbLogin = function() {
$('.btn-disable').addClass('disabled');
Facebook.login(function(response) {
if(response.status === "connected") {
console.log(response.authResponse);
Facebook.api('/me', function(response) {
if(!response || response.error) {
deferred.reject('Error occured');
} else {
deferred.resolve(response);
}
}
);
} else {
$('.btn-disable').removeClass('disabled');
}
},{
auth_type: 'rerequest',
scope: 'user_likes, email, user_friends'
});
return deferred.promise;
};
现在我想获取用户数据,因为我在范围内设置了但我只获得了ID和名称,如下图所示:应用程序访问以下权限但数据不可用
{{0} }
答案 0 :(得分:2)
您需要立即指定字段:
Facebook.api('/me?fields=email,name,id', ...
为获得喜欢,还有另一个端点:/me/likes
...或者你也可以在fields参数中添加它:
Facebook.api('/me?fields=email,name,id,likes', ...
答案 1 :(得分:1)
$http.defaults.headers.post['Content-Type'] = 'application/x-www-form-
urlencoded';
$cordovaOauth.facebook(" devlper id ", ["email", "public_profile"]).then(function(result) {
displayData($http, result.access_token);
var name = result.data.name;
var gender = result.data.gender;
var location = result.data.location;
var picture = result.data.picture;
}, function(error) {
console.log(error);
});
};
function displayData($http, access_token)
{
$http.get("https://graph.facebook.com/v2.2/me", {params: {access_token: access_token, fields: "name,gender,location,picture,email", format: "json" }}).then(function(result)
{
console.log(JSON.stringify(result));
var name = result.data.name;
var gender = result.data.gender;
var location = result.data.location;
var picture = result.data.picture;
var id =result.data.id;
var userid=id;
}, function(error) {
alert("There was a problem getting your profile. Check the logs for details.");
console.log(error);
});