jack
jack

Reputation: 1317

facebook check ask for additional permissions after user is logged in

Let's say I have an facebook application running using the JS SDK.

First user clicks on LINK A, and I do a call to FB.login() asking for the "email" permission.

<a href="#" onclick="doLogin();>LINK A</a>
<script>
function doLogin() {
FB.login(function (res) {
//res contains authResponse, i.e. the user is logged in.
}, { scope : 'email'} });
}
</script>

Then I will do a check on authResponse to check if user logged in or not.

if(res.authResponse) {
//User logged in
} else {
//User NOT logged in
}

NOW let's say that on LINK B, I want to ask for the "user_birthday" permission:

FB.login(function (res) {
//Now res.authResponse is set even if user did NOT grant access to the "user_birthday" permission
}, { scope : 'user_birthday'} });

However when the request for "user_birthday" is made the user is already logged in to the application - and therefore authResponse will be set regardless if user granted access to the additional permission, or clicked cancel.

Is there a way to check if user gave the additional permission?

I know I can do a lookup on the api on /me/permissions - but I wonder if there's a way to do it in the FB.login() callback?

Upvotes: 3

Views: 1212

Answers (1)

DMCS
DMCS

Reputation: 31870

Yes, using that user access token, query me/permissions.

FB.api('me/permissions',function(permsArr){
  var canGetBirthday = PermissionExists(permsArr, 'user_birthday'); // write your own PermissionsExists parser....
});

Upvotes: 2

Related Questions