hello.js
hello.js copied to clipboard
How to force hello.js to ask for email scope
Hi,
I have a scenario which is not working with hello.js.
I have set scope to email in the init with facebook as network. The user tries to login, declines email in facebook. Hello.js still logs him in and returns undefined email id for this user.
What I am doing is that for such users I am giving an error message that we need email id and asking them to login again. But this time when they click on login message, it does not display scope selector. Hence, such users are not able to login to the site.
How can i force scope check on login with hello.js?
With login you can use 'force' as an option, e.g. hello(network).login({force:true})
.
Facebook also lets us inspect the permissions afterwards. i.e. use facebook.api('me/permissions')
var facebook = hello('facebook');
facebook.login({
scope: 'email',
force: true
}).then(function() {
return facebook.api('me/permissions');
}).then(function(r) {
if (r.data.filter(function(item) {
return item.permission === 'email' && item.status !== 'granted'
}).length) {
throw new Error('missing permissions');
}
else {
return facebook.api('me');
}
}).then(successShowEmail, errorShowLoginButton);
Thanks for your input. It helped me with same issue
I recently created a new app on Facebook, set all the permissions, and the response does not act like the demos on your site for helloJS. In order to create a record in our DB, we need an email. But the email is not being returned. I have tried for a week using references of different gut hub and facebook help pages and still nothing. So I wanted to come to you directly. I am also using ng-hello given I our webapp uses angular. I don't believe that would be the issue, but it could be since the author hasn't updated the source code in over a year.
hello.on('auth.login', function(auth) {
// Call user information, for the given network
console.log(auth);
hello(auth.network).api('me',{
scope:'email',
force:true
})
.then(function(r) {
// Inject it into the container
console.log(r);
}, function(e) {
console.log(e);
});
});
Login function I use:
var facebook = hello('facebook');
facebook.login();
The response I get in return is:
{
first_name: *******
id: *******
last_name:*******
name: *******
picture: *******
thumbnail: *******
timezone: *******
verified: *******
}
I know that code changes all the time. I greatly appreciate your work Mr.Switch and would really appreciate any direction or assistance you could provide me for this situation. Thank you.
Hello bobby, Here is the way I used hello.js to retrieve the email and other data. Look at the code below and let me know if this was helpful.
var appId = "************";
function fblogin() { var facebook = hello('facebook'); facebook.login({ scope : 'email', force : true }).then(function() { return facebook.api('me/permissions'); }).then(function(r) { if (r.data.filter(function(item) { return item.permission === 'email' && item.status !== 'granted'; }).length) { throw new Error('missing permissions'); } else { return facebook.api('me'); }
}).then(function(p) {
jQuery.ajax({
type : "POST",
url :url_where_data_to_be_sent,
dataType : 'json',
data : {
info : p
},
success : function(data) {
//call custom function on success }
});
/*this is the response i am getting in console.log
email: "*********"
first_name: "******"
id: "***********"
last_name: ""***********""
name: "***********"
picture: "https://graph.facebook.com/***********/picture"
thumbnail: "https://graph.facebook.com/***********/picture"
timezone: 5.5
*/
//console.log(p);
});
}
hello.init({
facebook : FACEBOOK_CLIENT_ID
}, {
redirect_uri : site_url,
oauth_proxy : OAUTH_PROXY_URL
});
$(“#fb_login_btn”).on(“click”,function(){fblogin();});
@bobbyfisher928
You are meant to initiate hello.login
with the scope and force attribute, not hello.api
as you have done.
With google, this is what worked for me ..
In the hello.min.all.js files, find
scope: { basic:"https://www.googleapis.com/auth/plus.me profile, email:'email' ..
and replace with
basic:"https://www.googleapis.com/auth/plus.me profile,https://www.googleapis.com/auth/userinfo.email", email:'email' ..
Hi,
On top of forcing email scope, is there any way to rerequest user emails for facebook currently?
This is because once someone has declined a permission, the Login Dialog will not re-ask them for it unless you explicitly tell the dialog you're re-asking for a declined permission @ https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow
Ok silly me.
hello('facebook').login({ scope: 'email', force: true, auth_type: 'rerequest' }).then(function() { // do your stuff here });