FB.login not asking for permissions [duplicate] - javascript

This question already has answers here:
Facebook JS SDK's FB.api('/me') method doesn't return the fields I expect in Graph API v2.4+
(4 answers)
Closed 7 years ago.
I am trying to integrate FB login with my html website. I am using FB Javascript SDK version 2.5. The pop-up opens and ask the users for the userid and password but donnot ask for permissions like email, public profile, location etc although i have given the required permissions in the scope param. Below is my code.
HTML code:
<div id="btnFBLogin"> <img style="width: 35%"
src="assets/img/icons/facebookloginbutton.png" />
</div>
Initializing FB Javascript SDK and gets initialized on document load :
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXX',
xfbml : true,
oauth : true,
version : 'v2.5'
});
};
//Load SDK
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
Calling FB.login api:
$('#btnFBLogin').on('click',function(){
FB.login(function(response) {
console.log(JSON.stringify(response));
if (response.status === 'connected') {
// Logged into your app and Facebook.
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
});
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}, {scope: 'public_profile,email'});
});
The response object returned after login by FB.api('/me', function(response) gives only full name of the user logged in. It doesn't give me the email id although i have send it in the scope parameter.

you need to pass requested fields in url like
FB.api('/me?fields=id,first_name,last_name,friends,email',function(response)

Related

Javascript facebook login get email [duplicate]

This question already has answers here:
Facebook JS SDK's FB.api('/me') method doesn't return the fields I expect in Graph API v2.4+
(4 answers)
Closed 2 years ago.
I am trying to allow users to register and login on my site using facebook, the following code works and I can see the users name and ID in the response.
However, I am unsure how to get the email address of the user. I have checked that my app is live on facebook developers dashboard and the permissions and features section includes email.
FB.getLoginStatus(function(response){
if(response.status === 'connected'){
FB.api('/me', function(response){
console.log(response);
});
}
});
window.fbAsyncInit = function(){
FB.init({
appId:'326746698293638',
cookie:true,
xfbml:true,
version:'v7.0'
});
};
(function(d,s,id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document,'script','facebook-jssdk'));
Replace
FB.api('/me', function(response) { } )
by
FB.api('/me?fields=id,email,name', function(response) { } )
and make sure you are using scope email on the login function, like this
FB.login(function(response) {
// handle the response
}, {scope: 'email,user_likes'});
See docs for more details

Facebook login API "Can't Load Url: The domain of this URL isn't included in the app's domains"

Hi I am a beginner programmer trying to integrate facebook login in my mobile app. I have read through multiple similar questions but cannot seem to find a solution to the error. I have been following this javascript facebook login guide and have successfully logged in in through my browser. However, I am unable to log in through my mobile app, with the Error error : "Can't Load Url: The domain of this URL isn't included in the app's domains" I do not own any domains and am using localhost (XAMPP) and Eclipse emulator. Eclipse has also returned several errors like "Failed to find provider info for com.google.settings" and "pub com.android.browser.home: com.android.browser.homepages.Homeprovider" amongst others
shown here.
Here is what my the facebook interface looks like:
Developer pannel
shown here
Valid Oauth settings
shown here
Here is my javascript code:
<body>
<script type="text/javascript">
//initialize and setup facebook SDK
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXXXXXXXX',
xfbml : true,
version : 'v2.7'
});
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'We are connected';
// console.log('Logged in.');
}
else if (response.status === 'not_authorized'){
document.getElementById('status').innerHTML = 'We are not logged in';
}
else{
document.getElementById('status').innerHTML= 'facebook not logged in';
}
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src="https://connect.facebook.net/en_US/all.js";
//js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function login(){
FB.login(function(response){
if (response.status === 'connected') {
document.getElementById('status').innerHTML = 'We are connected';
//document.getElementById('login').style.visibility = 'hidden';
// console.log('Logged in.');
}
else if (response.status === 'not_authorized'){
document.getElementById('status').innerHTML = 'We are not logged in';
}
else{
document.getElementById('status').innerHTML= 'facebook not logged in';
}
}, {scope: 'email'});
}
</script>
hi
<div id="status"></div>
<button onclick="login()">Login</button>
</body>

Not Able to get email of user logged in via fb account in my site [duplicate]

This question already has an answer here:
Email scope is not working which is used in FB Login
(1 answer)
Closed 7 years ago.
I am making a site to make people login via their Facebook account.
I am able to fetch Name and the users image but I'm not getting users email. Email is returning as undefined. My code for Facebook login is:
window.fbAsyncInit = function() {
FB.init({
appId : 'XXXXXXXXXXXXXXXX', // Set YOUR APP ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
if (response.status === 'connected')
{
document.getElementById("message").innerHTML += "<br>";
}
else if (response.status === 'not_authorized')
{
}
});
};
function Login()
{
FB.login(function(response) {
if (response.authResponse)
{
getUserInfo();
getPhoto();
} else
{
console.log('User cancelled login or did not fully authorize.');
}
},{scope: 'email,user_photos,user_videos'});
}
function getUserInfo() {
FB.api('/me', function(response) {
var str="You have succesfully logged in<br>";
var name=response.name;
var email=response.email;
console.log(name+email);
});
$(document).ajaxStop(function(){
window.location.reload();
});
}
function getPhoto()
{
FB.api('/me/picture?type=normal', function(response) {
var str="<br/><b>Pic</b> : <img src='"+response.data.url+"'/>";
$('#getphoto').html(str);
});
}
function Logout()
{
FB.logout(function(){document.location.reload();});
}
// 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));
I've tried to get the email by all ways mentioned in Stack Overflow and developers.facebook.com, but failed.
Trigger for the Facebook login:
<img src='img/fblogin.jpg' onclick='login()'>
I tried to alert response properties by
for (key in response){ alert("response["+ key +"]="+ response[key]); }
it is returning name and id not email
I think issue is on your app that you have created on here https://developers.facebook.com/apps/
can you please make below changes first ?
login in https://developers.facebook.com/apps/ and open your app.
Click on "Status & Review" then find this "
Do you want to make this app and all its live features available to the general public?" make it yes.
After that check did you get email or not and let me know.

Facebook Canvas App cant login to Developer

when Try to login Facebook Canvas App only Developer can't login to App Show following Error
Invalid Scopes: read_friendlists. This message is only shown to
developers. Users of your app will ignore these permissions if
present. Please read the documentation for valid permissions at:
https://developers.facebook.com/docs/facebook-login/permissions
I use Following code inside index.php file and bottom of the code
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo APP_ID;?>',
xfbml : true,
version : 'v2.3'
});
function onLogin(response) {
if (response.status == 'connected') {
FB.api('/me?fields=first_name', function(data) {
var welcomeBlock = document.getElementById('fb-welcome');
welcomeBlock.innerHTML = 'Hello, ' + data.first_name + '!';
});
}
}
FB.getLoginStatus(function(response) {
// Check login status on load, and if the user is
// already logged in, go directly to the welcome message.
if (response.status == 'connected') {
onLogin(response);
} else {
// Otherwise, show Login dialog first.
FB.login(function(response) {
onLogin(response);
}, {scope: 'user_friends,email,read_friendlists'});
}
});
FB.Canvas.setAutoGrow();
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
This happen on 6th of may 2015, before that it works fine..
Check this link and check your api version.
https://developers.facebook.com/docs/facebook-login/permissions/v2.3
As per this link
"If you want to access a person's friends who also use your app, you should use the user_friends permission.
This permission will also not help you invite a person's friends to use your app. To learn more about how to invite friends to an app, please see our FAQs.
This permission also does not give the list of friends who are part of a friendlist. It only gives access to the names of the lists.
This permission was called read_friendlists before v2.3.
Review
If your app requests this permission Facebook will have to review how your app uses it."

Facebook logout by javascript

I am developing a simple web game with my friends. I have integrated facebook login using the javascript sdk provided by FB. Basically, the first page of the web game is main.html, in which I added successfully a Facebook button using the code provided by Facebook:
<script>
// This is called with the results from from FB.getLoginStatus().
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
// The response object is returned with a status field that lets the
// app know the current login status of the person.
// Full docs on the response object can be found in the documentation
// for FB.getLoginStatus().
if (response.status === 'connected') {
// Logged into your app and Facebook.
window.location.href = "mode.html";
} else if (response.status === 'not_authorized') {
// The person is logged into Facebook, but not your app.
document.getElementById('status').innerHTML = 'Please log ' +
'into this app.';
} else {
// The person is not logged into Facebook, so we're not sure if
// they are logged into this app or not.
document.getElementById('status').innerHTML = 'Please log ' +
'into Facebook.';
}
}
// This function is called when someone finishes with the Login
// Button. See the onlogin handler attached to it in the sample
// code below.
function checkLoginState() {
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
}
window.fbAsyncInit = function() {
FB.init({
appId : 'xxx',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.3' // use version 2.3
});
// Now that we've initialized the JavaScript SDK, we call
// FB.getLoginStatus(). This function gets the state of the
// person visiting this page and can return one of three states to
// the callback you provide. They can be:
//
// 1. Logged into your app ('connected')
// 2. Logged into Facebook, but not your app ('not_authorized')
// 3. Not logged into Facebook and can't tell if they are logged into
// your app or not.
//
// These three cases are handled in the callback function.
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
// Here we run a very simple test of the Graph API after login is
// successful. See statusChangeCallback() for when this call is made.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Successful login for: ' + response.name);
document.getElementById('status').innerHTML =
'Thanks for logging in, ' + response.name + '!';
});
}
</script>
<fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
</fb:login-button>
Once login is successful, the page would be directed to another html page. In that html page, I tried to add an Facebook logout button. Trying for some hours, in vain. The most frequent error obtained is something like "FB is underfined".
Finally I decided to download a .png of FB logout button and include this .png as src image to "make" a button by myself, still in vain, rather frustrating.
The code I included in that another html page is as follows.
<script>
// This is called with the results from from FB.getLoginStatus().
window.fbAsyncInit = function() {
FB.init({
appId : 'xxx',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.3' // use version 2.3
});
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function fbLogout() {
FB.logout(function (response) {
//Do what ever you want here when logged out like reloading the page
window.location.reload();
});
}
</script>
<button id="fblogout" onclick="fbLogout();""><img src="src/logout_fb.png"> </button>
The error I retrieved from the Chrome console is "Uncaught ReferenceError: fbLogout is not defined"
Have you tried using the "Enable logout button" at the plugin page: https://developers.facebook.com/docs/plugins/login-button
That will give you a button like this:
<div
class="fb-login-button"
data-max-rows="1"
data-size="medium"
data-show-faces="false"
data-auto-logout-link="true" />
If you use that code, you will either see a Login or Logout button, depending on the state. This can be used with the normal FB SDK for Javascript.

Categories

Resources