我正在使用facbook api访问facebook上的照片,为此我们需要获得许可但无法获得许可。我尝试了很多,但每次都被许可拒绝。
用于连接Facebook的脚本,并获取登录用户的个人资料图片:
<script src="angular.min.js"></script>
<script src="angular-facebook.js"></script>
<script>
angular.module('app', ['facebook'])
.config(function(FacebookProvider) {
FacebookProvider.init('386514074820288');
})
.controller('mainCtrl', function ($scope, Facebook) {
$scope.login = function () {
Facebook.login(function(response) {
console.log(response);
if (response.status == 'connected') {
$scope.status = 'Connected with Facebook';
} else {
$scope.status = 'Failed to connect with facebook';
}
});
//getting the user information who connect with facebook
Facebook.api('/me', function(response) {
console.log(response);
//getting the url for the profile picture from facebook
Facebook.api('/'+response.id+'/picture',function(respone) {
$scope.imgSrc = respone.data.url;
});
});
};
});
</script>
但是当我访问相册/照片时,我得到了空数组.....
Facebook.api('/me/photos', function(response) {
console.log(response);
//getting the url for the profile picture from facebook
Facebook.api('/'+response.id+'/picture',function(respone) {
$scope.imgSrc = respone.data.url;
});
});
当我在互联网上搜索时,我发现要访问照片,需要获得Facebook的许可。但是当我每次拒绝和未批准时都提交了获得许可的请求。
请告诉我如何获得许可?
答案 0 :(得分:0)
我认为你出错的地方是你没有为你的FB.login()函数提供一个范围对象。您需要传递到范围对象的权限是'user_photos'。
var permissions = ['user_photos'];
Facebook.login(function(response) {
console.log(response);
if (response.status == 'connected') {
$scope.status = 'Connected with Facebook';
} else {
$scope.status = 'Failed to connect with facebook';
}
}, {scope: permissions.join(', '), return_scopes: true });
As per the Facebook 通过在调用FB.login时在选项对象中将return_scopes选项设置为true,您将在authResponse对象的grantedScopes字段中收到已授予权限的列表。