Blog : How do I request permissions for users information?
How do I request permissions for users information?
I think this is a very obvious question, but I am completely stumped. I think I have setup my app settings correctly, but when I try to authenticate (with Javascript SDK) my account on my website and then console.log(me), I still only get public information.
EDIT: I think that my problem is that my website is using the "Current Dialog" and not the "Referral Dialog." I understand that the referral dialog is only used when someone is directed to my website through Facebook, but I know there must be a way to use the Referral Dialog from my website as well. Why would anyone even use the Current Dialog if it can only authenticate the server with a user's public information? I read another post that said I should look at the authentication doc (https://developers.facebook.com/docs/authentication/), but as far as I can see there is nothing there on authorizing with the Referral Dialog.
I want to use Javascript SDK. Is this possible or will I have to just do it without Javascript SDK?
In Auth Dialog, I have this: email, user_about_me, user_likes, user_location, user_website, user_checkins
Here is my code:
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
// Init the SDK upon load
window.fbAsyncInit = function() {
FB.init({
appId : '464723870207650', // App ID
channelUrl : '//'+window.location.hostname+'/scripts/channel.php', // Path to your Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// listen for and handle auth.statusChange events
FB.Event.subscribe('auth.statusChange', function(response) {
if (response.authResponse) {
// user has auth'd your app and is logged into Facebook
FB.api('/me', function(me){
console.log(me);
})
} else {
// user has not auth'd your app, or is not logged into Facebook
}
});
}
Just call the FB.login method along with the wanted permissions:
function login() {
FB.login(function(response) {
console.log("FB.login callback, response: ", response);
}, { scope: "email,publish_stream,etc" });
}
Just keep in mind that:
Calling FB.login results in the JS SDK attempting to open a popup window. As such, this method should only be called after a user click event, otherwise the popup window will be blocked by most browsers.