facebook login with javascript - server related issues? - javascript

I'm experiencing issues with login into FB account with javascript from our website.
The login is simple, we defined the scope: email, user_birthdate, ... what we need.
On one server I can all the info we need, on another only basic information, ie: birthdate is missing and hometown as well.
Is there any way to prevent this? It might be I missed something out.
Thanks for your suggestions.
   window.fbAsyncInit = function() {
   FB.init({
   appId : fb_app_id, // App ID
   apiKey : fb_app_secret,
channelURL : '', // Channel File, not required so leave empty
   status : false, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true, // parse XFBML
frictionlessRequests : true
   });
    function login(){
FB.getLoginStatus(function(response){
if(response.status === 'connected'
|| response.authResponse != null){
FB_response(response);
}
else{
FB.login(function(response) {
if(response.authResponse) {
//alert('connected' );
FB_response(response);
}
else {
// user is not logged in
}
},{scope:'email, user_about_me, user_birthday, user_hometown, user_location'});
}
});
}

I guess you try it with different users... All admin/tester/developer users of an app can give their permissions without the app being reviewed yet. All other users can't, and therefore you only see the basic info.
See
https://developers.facebook.com/docs/apps/review/login#do-you-need-review

Related

Facebook login status "connected" by only login on fb, but not on web app

in my web app I have a FB login button; when I access on FB and then go my web page, I correctly see the "Login" button and the "FB login button", because I have not given the access credentials yet. But launching a test function,on the console I see "status: connected", that tells me that I have accessed both on FB and my web app, while I am expecting "status: 'not_authorized'", because I acceded on FB but not on my web app...why?
Here's my code:
<script>
function statusChangeCallback(response) {
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected') { // Logged into app and Facebook
testAPI();
} else if (response.status==='not_authorized'){ // Logged into FB but not into app
alert("not_authorized");
} else {
document.getElementById('status').innerHTML='Log '+'into FB'; // not logged in FB
}
}
window.fbAsyncInit = function() {
FB.init({
appId : '',
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse social plugins on this page
version : 'v3.2' // use version 2.2
});
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
};
</script>

Deezer Javascript SDK login not working

I've been trying to login with javascript SDK. And I am trying to login with this code:
DZ.init({
appId : 'MY_APP_ID',
channelUrl : 'http://127.0.0.1/channel.html',
player: {
onload: function() {console.log('I am loaded')}
}
});
const login = () => {
DZ.login(function(response) {
console.log(response.authResponse);
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
DZ.api('/user/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {perms: 'basic_access,email'});
};
I am invoking login function with a login button. When login is invoked, new windows opens and asks to authorise the application, which is an expected behavior. But after this, it gets stuck as shown in the picture below:
And when I close the window, DZ does not get the access token although the access token is in the url as in the picture.
Is this a bug? Is there a way to initialize DZ with access token manually?
Also, my another qualm is that why js SDK does not need secret to initialize and login.

Facebook connect: can retrieve the id, the username but cannot retrieve the email

I can get the id and username from facebook connect, but I cannot retrieve the email !
Here is the JS script:
function connectionFacebook()
{ console.log('connectionFacebook called');
FB.api('/me?fields=email,name', { fields: 'name, email' }, function(response)
{
console.log(response);
response gives me:
Object {name: "John Doe ", id: "11112222333344445555"}
But no email !
PS. I guess it uses some old FB connect js since I work on an quite old site.
I have no idea what version of FB it uses, but I guess an old one !
ex: of code found in site;
FB.Event.subscribe('auth.login', function(response)
{
connectionFacebook();
;
});
FB.getLoginStatus(function(response)
{
if (response.authResponse)
{
connectionFacebook();
}
else
{
// no user session available, someone you dont know
//alert("getLoginStatus:deconnecté");
}
});
$.fn.connexionFacebook = function( ) {
return this.each(function () {
FB.init({
appId : xxxxxxxxx,
status : true,
cookie : true,
xfbml : true
});
});
}
})( jQuery );
<script src="http://connect.facebook.net/fr_FR/all.js"></script>
<fb:login-button show-faces="false" width="450" perms="email,user_birthday,user_location" size="medium">FaceBook connect</fb:login-button>
I'd guess that you don't have a permission to access the user's email. Facebook requires you to set the scope that determines which information you need to access.
In you case you need to specify the scope as public_profile,email to access the email. you can do that when your user logs in. Either with the API call:
FB.login(callback, { 'scope': 'public_profile,email' });
or with the button:
<fb:login-button scope="public_profile,email"></fb:login-button>
Specifying the email in the scope will ask the user to share her email address with your application when she logs in:

How to request permissions for facebook app with JavaScript

How can I check the current user login status and ask for permissions for my app? This recently changed and now my app is not working anymore. Thanks for your help!
I always use this setup to handle login status and permissions:
function getPerms() {
FB.login(function(response) {
if (response.authResponse) {
//user has granted permissions
}
}, {scope:"email, ..."});
}
function getStatus() {
FB.getLoginStatus(function(response) {
if (response.status === "connected") {
//user has granted permissions
} else {
getPerms();
}
});
}
You still have to include the all.js and call FB.init(...)
Here is how you can do that:
FB.init(
{
"appId" : xxxxxxxxxx,
"status" : true,
"cookie" : true,
"xfbml" : true,
"oauth" : true
});
FB.Event.subscribe('auth.authResponseChange', function(response)
{
// need to wait few seconds for fb login status to work in FireFox
setTimeout('window.location.reload()', 3000);
});
function fbConnect(){
FB.getLoginStatus(function(response) {
if (response.authResponse){
FB.login(function(response)
{
if (response.authResponse) { }
else
{
//console.log('User cancelled login or did not fully authorize.');
}
}, {"scope":"email,manage_pages"});
}
});
}
You need to call fbConnect() function.
Also make sure that you have these below <body> tag on your page:
<div id="fb-root"></div>
<script src="//connect.facebook.net/en_US/all.js"></script>
You need to provide some code to get better/accurate answers
Most likely you didn't upgrade your code to use OAuth 2.0, see here
Based on the link above, use scope instead of perms
Use response.authResponse instead of response.session
Welcome to Stackoverflow!

FB.api does not work when called right after FB.init

FB.api does not work when called right after FB.init. Here is the code snippet I use:
window.fbAsyncInit = function() {
FB.init({
appId : window.APP_ID,
status : true,
cookie : true,
oauth : true,
channelUrl : window.MASTER_URL + "channel",
frictionlessRequests : true
});
window.COMPANY.init();
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
And here is my COMPANY.init() and COMPANY.fetchAllFriends():
friends: new Array(),
init : function() {
// TODO
COMPANY.fetchAllFriends();
FB.Canvas.setSize($(document).height());
FB.Canvas.setAutoGrow();
},
fetchAllFriends : function() {
FB.api('/me/friends', function(response) {
if (!response || response.error) {
return;
}
COMPANY.friends = new Array();
$.each(response.data, function(index, value) {
COMPANY.friends.push(value.id);
});
});
},
where at fetchAllFriends response contains error which says "An active access token must be used to query information about the current user.". I made sure (via the browsers debugger) that FB.init is called before that call of FB.api.
Any help will be appreciated!
Ok, I fixed my problem. I changed:
window.fbAsyncInit = function() {
FB.init({
appId : window.APP_ID,
status : true,
cookie : true,
oauth : true,
channelUrl : window.MASTER_URL + "channel",
frictionlessRequests : true
});
window.COMPANY.init();
};
to:
window.fbAsyncInit = function() {
FB.init({
appId : window.APP_ID,
status : true,
cookie : true,
oauth : true,
channelUrl : window.MASTER_URL + "channel",
frictionlessRequests : true
});
FB.Event.subscribe('auth.login', window.COMPANY.init);
};
in case anyone else want to know. What I found is that the FB JS SDK has not formed the user session by the time when FB.init returns, so what you need to do is to subscribe to the 'auth.login' event with your init function. More info here
You don't appear to be checking the status of the user. All you are doing is initializing Facebook, you don't even know if the user is logged into Facebook or has a Facebook account. You need to call FB.getLoginStatus and check if they are "connected". If they aren't connected, there is no possible way to get an access token. If they are connected, then you get an access token.

Categories

Resources