Login button: doesn't work when user is logged in Facebook - facebook

edit: explanation:
When Facebook login button should appear and when not? On facebook tutorial page it is not accurately explained. There is written: "If the user is already logged in, no login button is shown". But for me, it is true only when user is logged in both in facebook profile and my facebook application connected to my website! It is not true, that button is removed when you are logged in just on facebook profile, as it is mentioned on the facebook tutorial. Am I right? –
could anybodey help?
thanks
tomas
//old message
I have Facebook login button on my website. Sometime visitors are logged in facebook byt are not logged into my website (my application on fb). In this case, Login buton is displayed but does nothing. As I know, Login button should not only log in facebook but also login to my application.
It works OK when user is logged out both from facebook and application (website) before clicked. But what if user is logged in just to facebook? Then my button does nothing.

You can render a button for connect session and another for those with out session.
Sample Usage: Using getLoginStatus() to determane if user is connected to app, and XFBML.parse to render the button. https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
I opted out of using channelURL but you can create your own and read about here. https://developers.facebook.com/docs/reference/javascript/
if user is connected and logged in, logout button appears.
if user is not connect but logged into facebook login button appears.
if no session or login login button appears.
Async JavaScript SDK
<div id="fb-root"></div>
<!-- build1 is where we render our button based on connected status. -->
<div id="build1"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'YourAppId',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
//channelUrl : 'http://WWW.MYDOMAIN.COM/channel.html', // channel.html file
oauth : true // enable OAuth 2.0
});
if (window!=window.top) {
FB.Canvas.setAutoResize();
}
FB.getLoginStatus(function(response) {
if (response.authResponse) {
// logged in and connected user, someone you know
// render button
Cbuild1 = document.getElementById('build1');
Cbuild1.innerHTML = "";
Cbuild1.innerHTML = "<fb:login-button autologoutlink=\"true\"></fb:login-button>";
FB.XFBML.parse(Cbuild1);
} else {
// no user session available, someone you dont know
// render button
Cbuild1 = document.getElementById('build1');
Cbuild1.innerHTML = "";
Cbuild1.innerHTML = "<fb:login-button></fb:login-button>";
FB.XFBML.parse(Cbuild1);
}
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
functionality of loginStatus tested here https://shawnsspace.com/fb.test.connect.loginbutton.php

I have the same problem. I tried Shawn E Carter 's solution and still no improvements.
But i observed the new parameter for oauth in the FB.init call. If i set it on true it works as expected.

Related

Facebook login popup blocked

I am using a Facebook app to authenticate my users, but if the user is not logged in to Facebook (I am checking it with FB.getLoginStatus()) I show him a button to log in with. The problem is that the pop-up gets blocked all the time. I have no idea why, since I am registering the Facebook log in action on ng-click.
<button type="button" ng-click="login()">Log in via Facebook</button>
...
$scope.login = function() {
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
$scope.userId = response.authResponse.userID
loginSuccess()
} else
FB.login(function(response) {
if (response.authResponse) {
$scope.userId = response.authResponse.userID
loginSuccess()
} else {
alert('You need to log in and authorize the app, otherwise you won\'t be able to take the quiz!')
}
})
})
}
Any help?
FB.getLoginStatus should be used on page load to check if the user is authorized and to refresh the User Token. You can use it right after FB.init and store the User ID if he is logged in.
FB.login must be used directly on user interaction, you are using it in the asynchronous (!) callback function of FB.getLoginStatus and not directly when the user clicks on the button.
Example: http://www.devils-heaven.com/facebook-javascript-sdk-login/

Facebook Logout issue

I'm using the following code to logout from Facebook.
string url = string.Format("https://m.facebook.com/logout.php?confirm=1&next={0}&access_token={1}",
ConfigurationManager.AppSettings["Facebooklogout"],
token)
Note :
ConfigurationManager.AppSettings["Facebooklogout"]="http://localhost:56481/MenUs.Web/REGISTRATION/userinterestgroups.aspx"
But instead of logging out, it's directing me to my Facebook profile page.
Please provide me a solution
There is m.facebook.com bug that says next is being ignored. You could always use https://www.facebook.com/logout instead.
Also your logout URL has to be in the domain of the app you registered on Facebook, localhost will not work.
string url = string.Format("https://www.facebook.com/logout?confirm=1&next={0}&access_token={1}",
ConfigurationManager.AppSettings["Facebooklogout"],
token)
Please take note above, the logout URL must be in the same domain as the app. So the above would not redirect to localhost:xxx
I have resolved the above issue long ago by using the following javascript on click of "Save Button".
<script type="text/javascript">
function logoutFacebook() {
}
window.onload = function () {
var ID = document.getElementById('hfID').value
FB.init({ apiKey: ID });
FB.getLoginStatus(handleSessionResponse);
}
function handleSessionResponse(response) {
FB.logout(handleSessionResponse);
}
</script>

Facebook login shows a blank page after giving permission on Windows Phone

I am building a mobile site where a user has to be able to login with his facebook account as described on http://developers.facebook.com/docs/guides/mobile/web/. It works on Iphone and Android devices but on Windows Phone it does not. This is what happens:
When I press the login button I get the facebook page where I have to give permission to use my facebook account.
After I give promission, it redirects to "https://www.facebook.com/dialog/permissions.request" and a blank page is shown. On Android the "window.FB.login" callback is called (see code below) where I can get the info and redirect the user but on Windows Phone it only shows that blank page. When I go to my facebook page, my site is registered in the app list. So the registration did work correctly.
The same thing happens when I try to login on the example page: http://www.facebookmobileweb.com/hello/.
Does anyone know how to make it work on Windows Phone? And is it even possilble? Because I found a lot of sites where this happens.
This is my code: (Once again this works on Android and Iphone devices).
var fbApi = {
init: function () {
$.getScript(document.location.protocol + '//connect.facebook.net/en_US/all.js', function () {
if (window.FB) {
window.FB.init({
appId: MY_APP_ID,
status: true,
cookie: true,
xfbml: false,
oauth: true,
});
}
});
},
login: function () {
/// <summary>
/// Login facebook button clicked
/// </summary>
log("login facebook button clicked");
if (window.FB) {
//Windows phone does not enter this method, Android and Iphone do
window.FB.login(function (response) {
if (response.status) {
log('it means the user has allowed to communicate with facebook');
fbAccessToken = response.authResponse.accessToken;
window.FB.api('/me', function (response) {
//get information of the facebook user.
loginService.subscribeSocialUser(response.id, response.first_name, response.last_name, fbAccessToken, "", "FaceBook", fbSucces, fbFail);
});
} else {
log('User cancelled login or did not fully authorize.');
}
},
{ scope: 'email'
});
}
}
};
I did it in an other way as described here: http://developers.facebook.com/docs/authentication/

Reveal website-content when facebook-page liked

I'm trying to reveal content on my website only to people who like my facebook page. I've tried severall tutorials but none of them work. The closest I got was following this:
http://www.dejanlevec.com/2011/05/11/how-to-display-certain-page-content-only-to-users-who-have-liked-our-page-on-facebook/
I can get it to work if I first dislike the page and then like it on the facebook_test.php . Thus it doesn't detect if I already like the page.
I have done this with javascript before using FB.Event.subscribe and edge.create as described below:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'APP_ID_HERE', status: true, cookie: true, xfbml: true});
FB.Event.subscribe('edge.create',
function (response) {
window.location = "http://redirectexamplehere.com";
});
FB.Event.subscribe('edge.create',
function (response) {
window.location = "http://redirectexamplehere.com";
});
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//]]>
</script>
This way a user will be redirected to wherever you specify upon them liking the page. Remember to load the SDK first or it won't work.
Detecting if a user likes you on a website is a bit trickier than in a Facebook page. You'll need to setup a Facebook application and use that on your website and have the user authenticate using the app in addition to liking your page. Once you have that connection with the user you can test to see if they are logged in and have liked your page. At that point you can display different types of content.
The extra step of having to authenticate the user is probably why you don't see this implemented on too many websites.

Facebook login hangs at "XD Proxy" when page is installed via Chrome Web Store

The created the following web application:
http://www.web-allbum.com/
I also added it to the Chrome Web Store:
https://chrome.google.com/webstore/detail/idalgghcnjhmnbgbeebpdolhgdpbcplf
The problem is that when go to the Chrome Web Store and install this app the Facebook login windows hangs at a "XD Proxy" window. While the connect itself works, this blank window can confuse the users.
I did my research, and this seems to be a Chrome issue:
https://code.google.com/p/chromium/issues/detail?id=59285#c26
If you uninstall the app from Chrome, the problem disappears.
Is there any workaround for this problem?
Similar stackoverflow questions:
Facebook connect login window locking in Chrome
FB.login dialog does not close on Google Chrome
facebook connect blank pop up on chrome
https://stackoverflow.com/questions/4423718/blank-page-with-fb-connect-js-sdk-on-after-permission-request
This is my Facebook connect in case it helps:
FB.init({
appId : window.__FACEBOOK_APP_ID__,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
channelUrl : window.__MEDIA_URL__ + 'channel.html', // channel.html file
oauth : true // enable OAuth 2.0
});
FB.XD.Flash.init();
FB.XD._transport = "flash";
if (A.networks.facebook.connected) {
FB.getLoginStatus(function (response) {
// Stores the current user ID for later use
that.network_id = response.authResponse.userID;
if (!response.authResponse) {
// no user session available, someone you dont know
A.networks.facebook.connected = false;
}
callback();
});
}
else {
callback();
}
};
The Solution
Thanks to the reekogi reply I was able to workaround this issue. Here is the full implementation:
In order to avoid the XD Proxy problem, you have to connecte to Facebook without using the FB.login, this can be achieved by manually redirecting the user to Facebook page.
I had this login function in my code:
_facebook.connect_to_network = function (callback) {
FB.login(function (response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function (response) {
// Stores the current user Id for later use
that.network_id = response.id;
console.log('Good to see you, ' + response.name + '.');
callback();
});
}
else {
console.log('User cancelled login or did not fully authorize.');
that.connected = false;
callback();
}
}, {scope: window.__FACEBOOK_PERMS__});
};
Which I replaced by this code:
_facebook.connect_to_network = function (callback) {
var url = 'https://www.facebook.com/connect/uiserver.php?app_id=' + window.__FACEBOOK_APP_ID__ + '&method=permissions.request&display=page&next=' + encodeURIComponent(window.__BASE_URL__ + 'authorize-window?my_app=facebook&my_method=login') + '&response_type=token&fbconnect=1&perms=' + window.__FACEBOOK_PERMS__;
window.open(url);
};
The new code opens a popup which connects to Facebook and returns to the url specified in the 'next' parameter. I added some extra parameters in this callback url so that the javascript code could check for it and close the popup.
This code is executed when the Facebook redirects to the callback url:
_facebook.parse_url_params = function () {
// This is the popup window
if (URL_PARAMS.my_method === 'login') {
window.opener.A.networks.facebook.connected = true;
self.close();
}
};
URL_PARAMS is just a helper object that contains all the url parameters.
I still believe that this is a Chrome issue, but since this workaround has worked and solved my problem I am marking this question as solved.
Could you call a javascript redirect to get permissions then redirect back to the http://www.web-allbum.com/connected uri?
I described this method in detail here ->
Permissions on fan page
EDIT:
The method I demonstrated before will be deprecated when OAuth 2.0 comes into the requirements.
Here is the code, adapted for OAauth 2.0 (response.session is replaced with response.authResponse)
<div id="fb-root"></div>
<script>
theAppId = "YOURAPPID";
redirectUri = "YOURREDIRECTURI"; //This is the page that you redirect to after the user accepts the permissions dialogue
//Connect to JS SDK
FB.init({
appId : theAppId,
cookie: true,
xfbml: true,
status: true,
channelURL : 'http://yourdomain.co.uk/channel.html', // channel.html file
oauth : true // enable OAuth 2.0
});
//Append to JS SDK to div.fb-root
(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);
}());
//Check login status and permissions
FB.getLoginStatus(function(response) {
if (response.authResponse) {
// logged in and connected user, someone you know
} else {
//Redirect to permissions dialogue
top.location="https://www.facebook.com/connect/uiserver.php?app_id=" + theAppId + "&method=permissions.request&display=page&next=" + redirectUri + "&response_type=token&fbconnect=1&perms=email,read_stream,publish_stream,offline_access";
}
});
</script>
Just tried and tested, worked fine in chrome.
I didn't try the solution proposed by Cesar, because I prefer to stick with Facebook's official javascript SDK.
Nevertheless I would like to add a few observations:
Indeed, the blocking problem only happened on Chrome after installing from Chrome Web Store. Uninstalling the web app solves the problem. (tested with legacy authentication method, without oauth 2.0). After closing the XD Proxy popup manually, my application was working properly.
After switching to asynchronous FB.init() and enabling oauth 2.0 option, my application would not even get a valid facebook connect status at login time ({authResponse: null, status: "unknown"})... Again, uninstalling it from the Chrome Web Store, it's working... ({authResponse: Object, status: "connected"})
No problem encountered with Safari, in any of these cases.
In IE8 - this can be caused by your flash version. I tried everything and nothing worked until I disabled flash. More details from this blog:http://hustoknow.blogspot.com/2011/06/how-facebooks-xdproxyphp-seemed-to-have.html#comment-form
Open a new browser tab in Chrome and see if you have the Facebook 'App' installed. If so, drag it to the bottom right corner to uninstall. Once uninstalled the XD Proxy will work.
Reference: facebook connect blank pop up on chrome
I was experiencing same problem for all browsers. When user clicked "login" button, a popup opened and hanged; and unless user killed browser process, it caused a high load on CPU. If user managed to see "allow" button and click it however, then it appeared a "xd proxy" blank window and nothing happened. That was the problem.
After long investigations, I noticed my new JS code which proxies setInterval/clearInterval/setTimeout/clearTimeout methods, caused this problem. Code is as follows:
window.timeoutList = new Array();
window.intervalList = new Array();
window.oldSetTimeout = window.setTimeout;
window.oldSetInterval = window.setInterval;
window.oldClearTimeout = window.clearTimeout;
window.oldClearInterval = window.clearInterval;
window.setTimeout = function(code, delay) {
window.timeoutList.push(window.oldSetTimeout(code, delay));
};
window.clearTimeout = function(id) {
var ind = window.timeoutList.indexOf(id);
if(ind >= 0) {
window.timeoutList.splice(ind, 1);
}
window.oldClearTimeout(id);
};
window.setInterval = function(code, delay) {
window.intervalList.push(window.oldSetInterval(code, delay));
};
window.clearInterval = function(id) {
var ind = window.intervalList.indexOf(id);
if(ind >= 0) {
window.intervalList.splice(ind, 1);
}
window.oldClearInterval(id);
};
window.clearAllTimeouts = function() {
for(var i in window.timeoutList) {
window.oldClearTimeout(window.timeoutList[i]);
}
window.timeoutList = new Array();
};
window.clearAllIntervals = function() {
for(var i in window.intervalList) {
window.oldClearInterval(window.intervalList[i]);
}
window.intervalList = new Array();
};
Removing these lines solved my problem. Maybe it helps to who experiences the same.
It appears this has been fixed in Chrome. No longer happens for us in Mac Chrome 15.0.874.106
Another workaround is to use this code after you call FB.init():
if (/chrome/.test(navigator.userAgent.toLowerCase())) {
FB.XD._origin = window.location.protocol + '//' + document.domain + '/' + FB.guid();
FB.XD.Flash.init();
FB.XD._transport = 'flash';
}
The pop-up window remains open and blank, but I found that in my Chrome Web Store app, the authentication goes through when this code is used.
This bug is also filed on Facebook Developers here: http://developers.facebook.com/bugs/278247488872084
I've been experiencing the same issue in IE9, and it seemed to stem from upgrading to Flash Player 10. The answers suggested already did not work for me and I'd lost hope in trying to fix it since finding an open bug at Facebook covering it. But Henson has posted an answer on a similar question that fixed it for me. In the JavaScript in my site master I removed the lines
FB.UIServer.setLoadedNode = function (a, b) {
//HACK: http://bugs.developers.facebook.net/show_bug.cgi?id=20168
FB.UIServer._loadedNodes[a.id] = b;
};
and now it works. (N.B. I have not checked to see if the IE8 issue those lines were intended to overcome returns.)