Fetching extra fields from fb
I need to fetch other data like books, profile picture etc in the auth token. Even though my fb app has these permissions, the data isn't be fetched on authentication. Is it something related to lines of code below? I even tried adding the fields I need to the json below, but the result didn't change. What to do? Please help out. I don't want to explicitly make requests for each field.
angular.forEach({
'auth.login': 'login',
'auth.logout': 'logout',
'auth.prompt': 'prompt',
'auth.sessionChange': 'sessionChange',
'auth.statusChange': 'statusChange',
'auth.authResponseChange': 'authResponseChange',
'xfbml.render': 'xfbmlRender',
'edge.create': 'like',
'edge.remove': 'unlike',
'comment.create': 'comment',
'comment.remove': 'uncomment',
'books': 'books',
'books.reads': 'books_read',
'books.rates': 'books_rate',
'books.quotes': 'books_quotes',
'books.wants_to_read': 'wants_to_read',
'picture': 'picture'
}, function(mapped, name) {
FB.Event.subscribe(name, function(response) {
$timeout(function() {
$rootScope.$broadcast('Facebook:' + mapped, response);
});
});
});
I am having the same problem. How to modify the permission?
I am still stuck at the same issue. Can anyone help with this?
$scope.login = function () {
Facebook.login(function (response) {
if (response.status == 'connected') {
$scope.loginTrue = true;
$scope.me();
}
}, {scope: 'email,user_likes'}
);
};
// add the permissions like the above code indicated
Hi, @daiyong2010 This is not working for me. Let me know where I am wrong. It's still giving me the basic details only.
$scope.login = function(){
Facebook.login(function(response) {
if (response.status == 'connected') {
$scope.loginTrue = true;
$scope.me();
}
}, {scope: 'public_profile, email, user_actions.books, user_birthday, user_location'});
};
Hi, @saurabh-p Can you try email only at the first place to see whether my code work or not. For your reference, I put the whole Facebook controller here.
.controller('facebookAuthenticationController', ['$scope', 'Facebook', '$timeout', 'APIService','$cookies','$http','$location', function ($scope, Facebook, $timeout, APIService,$cookies,$http,$location) { $scope.user = {};
// Defining user loginTrue status
$scope.loginTrue = false;
// And some fancy flags to display messages upon user status change
$scope.byebye = false;
$scope.salutation = false;
/**
* Watch for Facebook to be ready.
* There's also the event that could be used
*/
$scope.$watch(
function () {
return Facebook.isReady();
},
function (newVal) {
if (newVal)
$scope.facebookReady = true;
}
);
Facebook.getLoginStatus(function (response) {
if (response.status == 'connected') {
$scope.loginTrue = true;
}
});
$scope.IntentLogin = function () {
if (!$scope.loginTrue) {
$scope.login();
}
};
$scope.login = function () {
Facebook.login(function (response) {
if (response.status == 'connected') {
$scope.loginTrue = true;
$scope.me();
}
}, {scope: 'email,user_likes'}
);
};
$scope.me = function () {
Facebook.api('/me', function (response) {
/**
* Using $scope.$apply since this happens outside angular framework.
*/
$scope.$apply(function () {
$scope.user = response;
console.log(response)
});
});
};
$scope.logout = function () {
Facebook.logout(function () {
$scope.$apply(function () {
$scope.user = {};
$scope.loginTrue = false;
});
});
}
/**
* Taking approach of Events :D
*/
$scope.$on('Facebook:statusChange', function (ev, data) {
console.log('Status: ', data);
if (data.status == 'connected') {
$scope.$apply(function () {
$scope.salutation = true;
$scope.byebye = false;
APIService.socialLogin('facebook', data.authResponse.accessToken).then(
function (response) {
if (response.data) {
console.log(response)
$cookies.auth_token = response.data.auth_token;
$cookies.username = response.data.username;
$http.defaults.headers.common.Authorization = 'Token ' + $cookies.auth_token;
$location.path('/ugc.html')
} else {
alert("Facebook Login Error.");
}
},
function (error) {
alert("Facebook Login Error!");
}
)
});
} else {
$scope.$apply(function () {
$scope.salutation = false;
$scope.byebye = true;
// Dismiss byebye message after two seconds
$timeout(function () {
$scope.byebye = false;
}, 2000)
});
}
}
)
}
]
)
No effect. Tried with only email also. Is it working for you?
Seems to be broken atm :/
+1
Try this with the fields that you need
FB.api("/me", {fields: "id,name,picture"}, function(response){
console.log('Facebook data'+JSON.stringify(response));
}
Following should work:
$scope.fbLogin = function() {
Facebook.login(function(response) {
},{scope: 'email'});
};
Don't forget that if you want additional fields other than email or user_friends you will need to submit your app for review by Facebook first:
https://developers.facebook.com/docs/facebook-login/permissions/v2.3#review https://developers.facebook.com/docs/facebook-login/permissions/v2.3#categories
I believe you can however add a test user to the app settings that will allow you to develop and test getting additional info without this restriction:
https://developers.facebook.com/docs/apps/test-users