Why Facebook Login API don't ask email access? - javascript

Guys I have a custom button which trigger an FB.login() event but I can't get email info, facebook don't ask an email access to user and return name, id fields
FB.login(function(response) {
console.log(response)
if (response.authResponse) {
FB.api('/me?fields=id,name,email', function(data) {
console.log(data)
if ((typeof data.email === 'undefined') ||(data.email == '') || (data.email == null)) {
M.toast({html: "You dont't give an email access, we are can't register you without email. Sorry :("});
return false;
}
window.flags.signin = {
status: true,
name_surname: data.name,
email: data.email,
login_type: 'facebook',
id: data.id
}
// back-end request func
window.flags.submitFunc('veriler='+JSON.stringify(window.flags.signin));
}, { scope: 'id,name,email'});
}
else {
M.toast({html: 'User cancelled login or did not fully authorize.'});
}
});

Repair it,
I change this line
{ scope: 'id,name,email'}
to
{ scope: 'email'}
and it's started ask to email access

Related

Permissions with Facebook Login - publish_actions permission not getting

In my website, users can post to their FB wall from my website. I,am using graph api for that. My api code is,
FB.api(
"/me/photos",
"POST",
{
"caption": "My caption",
"url": "My image url"
},
function (response) { console.log(response);
if (response && !response.error) {
$('#post_response').html('See feed');
}
}
);
During this api call getting an error,
code: 200
message: "(#200) Requires extended permission: publish_actions"
type: "OAuthException"
My Fb login Api is,
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
},
{
scope: 'email,public_profile,publish_actions,manage_pages',
auth_type: 'rerequest',
return_scopes: true
}
);
I also tried,
1)
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
},
{
scope: 'publish_actions'
}
);
2)
FB.login(function(response) {
if (response.authResponse) {
//user just authorized your app
document.getElementById('loginBtn').style.display = 'none';
getUserData();
}
},
{
scope: 'publish_actions',
auth_type: 'rerequest'
}
);
By calling api,
FB.api("/me/permissions", function (response) {
console.log(response);
});
I understood that, only getting 'email,public_profile' permissions.
How to get 'publish_actions' permission??
Is there any other methods to do this?? I want to post image post to users wall and users page...
Please help me to fix this issue...
Thanks in advance.
Make sure that you have added the FB account to test user under FB app settings >test user . Because In order to use permissions like publish _action your app needs to be approved by Facebook,but with test users you can test the functionalities.

Meteor.loginWithFacebook not storing email address

I'm using
accounts-password
accounts-facebook
service-configuration
On the server:
ServiceConfiguration.configurations.remove({
service: 'facebook'
});
ServiceConfiguration.configurations.upsert(
{ service: 'facebook' },
{ $set: {
appId: 'xxxxxxxxxxxxxxxx',
secret: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
}
}
);
On the client:
Meteor.loginWithFacebook({requestPermissions: ['email']}, function(error){
if (error) {
throwError('Could not log in');
} else {
// success
}
});
This configuration prompts the user for Facebook verification with access to email and returns no errors. A new user is stores with the correct name and ID. But this e-mail is not stored in the user object.
This is what I get when i fetch a user from the shell.
{ _id: 'xxxxxxxxxxxxxxxxx',
createdAt: Mon Jul 13 2015 13:36:21 GMT+0200 (CEST),
services:
{ facebook:
{ accessToken: 'xxxxxxxxxxxxxxxxxxxxx...',
expiresAt: 1441971380621,
id: 'xxxxxxxxxxxxxxxxx',
name: 'xxxx xxxxxx' },
resume: { loginTokens: [Object] } },
profile: { name: 'xxxx xxxxxx' } }
Why is the email address from Facebook not being stored?
While I have reported the issue to Meteor I've found a quick fix for the time being.
On the server run this:
Accounts.onCreateUser(function(options, user) {
if (user.hasOwnProperty('services') && user.services.hasOwnProperty('facebook') ) {
var fb = user.services.facebook;
var result = Meteor.http.get('https://graph.facebook.com/v2.4/' + fb.id + '?access_token=' + fb.accessToken + '&fields=name,email');
if (!result.error) {
_.extend(user, {
"emails": [{"address": result.data.email, "verified": false}],
"profile": {"name": result.data.name}
});
}
}
return user;
});
[EDIT]
The previous code works, but since it causes problems with other login methods I went with another approach:
In the client I call a function on the server when the user authenticates with Facebook:
Meteor.loginWithFacebook({requestPermissions: ['email']}, function(error){
if (error) {
//error
} else {
Meteor.call('fbAddEmail');
}
});
And then on the server:
Meteor.startup(function () {
Meteor.methods({
fbAddEmail: function() {
var user = Meteor.user();
if (user.hasOwnProperty('services') && user.services.hasOwnProperty('facebook') ) {
var fb = user.services.facebook;
var result = Meteor.http.get('https://graph.facebook.com/v2.4/' + fb.id + '?access_token=' + fb.accessToken + '&fields=name,email');
if (!result.error) {
Meteor.users.update({_id: user._id}, {
$addToSet: { "emails": {
'address': result.data.email,
'verified': false
}}
});
}
}
}
});
});
Facebook API may not return the email address for some users even if you asked for the "email" permission. The official API docs state that:
[email] field will not be returned if no valid email address is available.
One of the reason may be an unconfirmed email address and another one a user who registered with a mobile phone number only.

Meteor: Accounts.sendVerificationEmail customising behavior

Can someone please provide the correct method to send an email verification upon user creation? This is the important part...
a) I would like the user to have immediate access upon signing up. But if the user has not yet clicked clicked on the verification link within 48 hours, I would like to deny them logging in until they have clicked on the link.
My code so far sends an email verification but the user has continuos access to the application with or without clicking on the verification link (so my code is of course incomplete).
client.js
Template.join.events({
'submit #join-form': function(e,t){
e.preventDefault();
var firstName= t.find('#join-firstName').value,
lastName= t.find('#join-lastName').value,
email = t.find('#join-email').value,
password = t.find('#join-password').value,
username = firstName.substring(0) + '.' + lastName.substring(0),
profile = {
fullname: firstName + ' ' + lastName
};
Accounts.createUser({
email: email,
username: username,
password: password,
userType: // 'reader' or 'publisher'
createdAt: new Date(),
profile: profile
}, function(error) {
if (error) {
alert(error);
} else {
Router.go('home');
}
});
}
});
server.js
Meteor.startup(function () {
process.env.MAIL_URL = 'smtp://postmaster.....';
Accounts.emailTemplates.from = "no-reply#mydomain.com";
Accounts.emailTemplates.sitename = "My SIte Name";
Accounts.emailTemplates.verifyEmail.subject = function(user) {
return 'Please confirm tour Email address' ;
},
Accounts.emailTemplates.verifyEmail.text = function(user, url) {
return 'Click on the link below to verify your address: ' + url;
}
Accounts.config({
sendVerificationEmail: true
});
My attempt have been made through own readings on meteor docs and looking at other code on SO. I am stuck guys. Thanks for the support.
I think the basic idea is to have some validation code eg in Accounts.validateLoginAttempt which you want to check every time before user logs in. What you can do is to store the date&time when user signs up in user.profile.joinDate. If a user tries to login
Check if the email address has been verified or
check if the user is logging within the grace period of 48 hrs
isWithinGracePeriod = function(user) {
** TBD returning true or false.
This can be tricky when you
have multiple instances in
different time-zones.
** }
and
Accounts.validateLoginAttempt(function(attempt){
if (attempt.user && attempt.user.emails && !attempt.user.emails[0].verified ) {
console.log('No verification action received yet.');
return isWithinGracePeriod(attempt.user);
}
return true;
});
Further, here is the HTML/spacebars stuff:
<body>
{{ > start }}
</body>
<template name="start">
{{#if currentUser}}{{>showUserProfile}}{{else}}{{> login}}{{/if}}
</template>
<template name="login">
## Grab username/password here
</template>
If the login template is created, we can try to capture the verification code after the user clicked the verification link. Note that, if no user is logged in, then login will be rendered, so we attach to login via
Template.login.created = function() {
if (Accounts._verifyEmailToken) {
Accounts.verifyEmail(Accounts._verifyEmailToken, function(err) {
if (err != null) {
if (err.message = 'Verify email link expired [403]') {
var message ='Sorry this verification link has expired.';
console.log(message);
alertBox = Blaze.renderWithData(Template.Alert, {message: message}, $("body").get(0));
}
} else {
var message = "Thank you! Your email address has been confirmed.";
console.log(message);
alertBox = Blaze.renderWithData(Template.Alert, {message: message}, $("body").get(0));
}
});
}
};
The verification link is send in "hook" to Accounts.createUser:
Accounts.onCreateUser(function(options, user) {
user.profile = {};
Meteor.setTimeout(function() {
Accounts.sendVerificationEmail(user._id);
}, 2 * 3000);
return user;
});

Facebook wall post error : The user hasn't authorized the application to [duplicate]

This question already has an answer here:
(#200) The user hasn't authorized the application to perform this action
(1 answer)
Closed 8 years ago.
got error when i want to post text in facebook wall .
this is my code
function logout() {
FB.logout(function(response) {
alert('logged out');
});
}
// i am able to login successful . using this method .
function login() {
FB.login(function(response) {
if (response.authResponse) {
var access_token = FB.getAuthResponse()['accessToken'];
alert('Access Token = ' + access_token);
alert("Welcome! Fetching your information.... ");
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
alert("User cancelled login or did not fully authorize.");
console.log('User cancelled login or did not fully authorize.');
}
},{
scope: 'publish_actions',
return_scopes: true
});
}
// here i call this method to post the text in FB wall . and i am getting status logged in a but i got error .
function SubmitPost() {
FB.getLoginStatus(function(response) {
if (response.status == 'connected') {
alert('logged in');
try {
var wallPost = {
message: "post in fb" ,
picture: '',
link: '',
name: 'test app posted in your wall',
caption: '',
description: ('Test description')
};
FB.api('/me/feed', 'post', wallPost, function (response) {
if (!response || response.error) {
/*action*/
alert('Message could not be Posted.');
alert(response.error.message);
console.log(response.error.message);
} else {
/*action*/
alert('Message Posted successfully.');
}
});
}
catch (err) { alert('SubmitPost: ' + err);
}
} else {
alert('not logged in');
}
});
}
Please check your host URL matches with the URL given in the Facebook app "Website URL". Both should be exactly same.
If your are not added in facebook Website URL which reside under your App setting , then you can create this by hitting to "Add Platform" .
Steps to get website URL for the Facebook application:
1] If you are not created facebook app , To create Goto
https://developers.facebook.com/?ref=pf
2] Select Apps -> Create a new app
3] Fill the app details in the popup. Click on Create App
4] You will be redirected to dashboard page of your newly created application.
[ Note down the AppID]
5] Then click on "Settings" present at left side and then click on Add Platform
6] Choose "Website" from the popup menu.
7] Now you can find 2 fields : Site URL and Mobile Site URL.
Here you should fill your website URL where your are calling facebook SDK.

Why is the Facebook login not asking for correct permissions?

I use Facebook login using FB.login (and I don't want to use the Facebook login button). My problem is that after login, the Facebook dialog don't show the listed permission, as follows.
FB.login(function (response) {
if (response.status == "connected") {
//alert(" connected ");
}
else {
//alert(" not connected ");
}
}, { scope: 'email' });
The Facebook dialog show "Access my basic information" only. How do I fix this problem?
Note: if I try the Facebook login, it shows the permission correctly.
Note 2: the response after the user clicks Allow is:
User cancelled login or did not fully authorize.
That's because of a mistake in the official documentation.
The property name for the permissions is not "scope", but "perms":
FB.login(function (response) {
if (response.status == "connected") {
//alert(" connected ");
}
else {
//alert(" not connected ");
}
}, { perms: 'email' });

Categories