Topic-icon Facebook Permissions

Active Subscriptions:

None
13 years 3 months ago #31418 by fb_100000532508192
Hi,
I'm looking at ways to add permissions that are needed as and when my site grows. e.g. if i develop a service to manage pages, only when a user enables the service will they then see a popup asking for the relavant permissions. I have found the fb code and would like to know how to implement it via the jfbconnect api. Below is the code i found:
facebook permissions


Login
Check Permissions
Remove Permissions




FB.init({
appId : 'YOUR_APP_ID',
status : true, // check login status
cookie : true, // enable cookies
xfbml : true, // parse XFBML
oauth : true // enable OAuth 2.0
});

// Permissions that are needed for the app
var permsNeeded = ;

// Function that checks needed user permissions
var checkPermissions = function() {
FB.api('/me/permissions', function(response) {
var permsArray = response.data[0];

var permsToPrompt = [];
for (var i in permsNeeded) {
if (permsArray[permsNeeded] == null) {
permsToPrompt.push(permsNeeded);
}
}

if (permsToPrompt.length > 0) {
alert('Need to re-prompt user for permissions: ' +
permsToPrompt.join(','));
promptForPerms(permsToPrompt);
} else {
alert('No need to prompt for any permissions');
}
});
};

// Re-prompt user for missing permissions
var promptForPerms = function(perms) {
FB.login(function(response) {
console.log(response);
}, {scope: perms.join(',')});
};

var removePermissions = function(perms) {
FB.api(
{
method: 'auth.revokeExtendedPermission',
perm: perms.join(',')
},
function(response) {
console.log(response);
}
);
};

document.getElementById("login").onclick = function() {
FB.login(function(response) {
console.log(response);
}, {scope: permsNeeded.join(',')});
};

document.getElementById('checkPerms').onclick = function() {
checkPermissions();
};

document.getElementById('removePerms').onclick = function() {
removePermissions();
};




I did try to add some of the code but i broke the login part of the site. I'm assuming that jfbconnect declares it's own global variable(wrapper) to then interact with the facebook library. So it should need a few changes of the above code to have it working with jfbconnect.

many Thanks in advanced
The topic has been locked.
Support Specialist
13 years 3 months ago #31441 by alzander
Replied by alzander on topic Facebook Permissions
The code above should actually work in tandem with JFBConnect *except* you'd need to remove that FB.init call. That is already done by JFBConnect and would cause issues.

You can re-call the FB.login call however you want. JFBConnect calls it with the scope we know we need (usually for profile import), but if you call it again with your own scope, those new permissions will be requested if they haven't already been granted. If they have previously been granted, nothing actually happens (which is good).

Hope that helps, but if you still run into issues, let us know.

Thanks,
Alex
The topic has been locked.