I've integrated facebook login with my application and I want to logout the user from facebook when he logs out of my application. So I did the following:
Logout
This works on Firefox and Chrome but doesn't work on IE8. In IE8 the user is logged out of the application but is not logged out of Facebook.
Anyone else experiencing this?
Please try this one
<script src="http://connect.facebook.net/en_US/all.js"></script>
<div id="fb-root"></div>
<script language="javascript" type="text/javascript">
FB.init({
appId: '205734987138498',
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
oauth: true // enable OAuth 2.0
});
function handleSessionResponse(response) {
// FB.XFBML.parse();
}
FB.getLoginStatus(handleSessionResponse);
//////you can optionally put the following in a seprate js file/////////
var Facebook = {}
Facebook.signout = function (url) {
FB.logout();
setTimeout('top.location.href = "' + url + '"', 2000);
}
</script>
<div onclick="Facebook.signout('http://www.uamplify.com');">Call your logout function now, click here</div>
I found the exact same thing and also with the Android browser. Shahid's fix worked for me and then I realized another approach would be to put the redirect within the callback function like this:
function mysignout(url)
{
FB.logout(function()
{
top.location.href = 'url'
});
}
If you're like me, you probably figured FB.logout is just destroying a cookie or something but it appears to make some ajax calls (I guess to revoke authentication on the server) and has different execution times, especially on mobile devices using wireless networks.
2000 ms might not necessarily be enough time for the function to complete, or it could be more than necessary. The callback function executes once FB.logout has completed in every case.
Related
I was searching all possible topics but now solution works for me.
There is my code, which works in all browsers except Chrome. There is just window with An error occurred. Please try again later..
It is identical code from FB documentation.
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : {$appId},
frictionlessRequests: true
});
function sendRequestViaMultiFriendSelector() {
FB.ui({ method: 'apprequests',
message: '{_"FACEBOOK_INVITE_WINDOW_MESSAGE"}'
}, requestCallback);
}
function requestCallback(response) {
//callback code
}
</script>
<a onclick="sendRequestViaMultiFriendSelector(); return false;">
This might be because your application is still in sandbox mode.
You have to specify the display option for the dialog ('popup, 'iframe'...)
For example:
FB.init({
appId : {$appId},
frictionlessRequests: true,
display: 'popup'
});
You have not stated if your application is on Facebook or not. The reason this is important is because of the canvas_url parameter of your application settings. If you are on apps.facebook.com/app_namespace, then you'll already have this field filled out. However some projects simply do not operate on Facebook itself. In such cases people don't really "need" to fill in this parameter. It is however necessary for app requests to work.
When a user acts on an application request (IE accepts it), they are redirected to the canvas url of that application. Not specifying the canvas url can nullify the request. This might also be the reason for the error.
Try setting your canvas url. You can even have it redirect to your proper URL, it doesn't have to "do" anything else.
We are getting a permission denied error in IE8. It happens after the FB.init. We have tried the channelUrl fix. We have put the as the first tag after the body. We have tried the document.domain in both the script and in the channel.html. We have tried the FB.UIServer.setActiveNode workaround.
It works fine in IE9, FF, Chrome and Safari.
<div id="fb-root"></div>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
var myUserId;
document.domain = 'XXXX.XXXX.com';
window.fbAsyncInit = function() {
FB.init({ appId: 'XXXXXXXXX',
status: true,`enter code here`
cookie: true,
xfbml: true,
channelUrl: 'http://XXX.XXXX.com/channel.html'
});
FB.UIServer.setActiveNode = function(a, b) { FB.UIServer._active[a.id] = b; } // IE hack to correct FB bug
I am getting an permission denied error in IE8 in a facebook-iframe for a tab app on a facebook-fanpage. Any ideas how to fix this?
This worked for me:
FB.init({
appId: 'xxxxx',
appSecret: 'xxxxxxxxx',
status: true
cookie: true
});
// this code solves the issue
FB.UIServer.setLoadedNode = function (a, b) {
FB.UIServer._loadedNodes[a.id] = b;
};
As seen here http://ikorolchuk.blogspot.com/2011/09/facebook-javascript-sdk-security-error.html?showComment=1323866805727#c7681567069563597438
I'd suggest attaching the debugger and posting exactly where the error occurs. If its related the Facebook Proxy it might be a temporary issue with Facebook.
A couple of suggestions ( not mentioned above ):
1/ Try adding FBML to your html tag:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xml:lang="en">
2/ Try disabling compatibility mode options if your are accessing a test server that might be considered an intranet site ( generally same subnet ).
It is possibly because you redirect to a HTTP page while your current iframe is https.
The protocol of the iframe can be https, maybe because of an internal redirect, even if the Facebook page is http.
I saw a website today that stated: "Share/Like this site and get 10% discount". I was wondering: is there any way to track when someone shares/likes my site? Can I store some data of that user in my app?
I know those events have some callbacks, and maybe I can trigger some jQuery magic to send some data vía ajax when the user clicks on the button.
Any ideas?
Thanks!
Similar question was discussed here
FB.Event.subscribe('edge.create', function(href)
{
});
From the above code you can get only href not any User details. So I tired the following code
FB.Event.subscribe('edge.create', function (href) {
FB.login(function (response) {
if (response.session) {
//session object has uid & access token.
}
});
});
The Problem you will have from above code is: Since FB.login will open a pop up window for log in, some browsers will block the pop up or warns the user.
I tried the above code. LIKE functionality works and is posted to user's wall, but regarding getting user info:
Firefox (4.0) - did not warn but it asked the user to authorize APP and access basic information. IE 9 - Gave a warning message about POP UP. Google Chrome : Blocked the log in pop up.
It seems the only way to achieve this is let the user login to website using Facebook Connect first and then get user info using
FB.Event.subscribe('edge.create', function (href) {
// href is the URL of the object that got liked
var x;
FB.getLoginStatus(function (response) {
alert(response);
if (response.session) {
}
});
Check out the Facebook developers site. It contains heaps of information.
http://developers.facebook.com/search?q=Events.create
and
http://developers.facebook.com/blog/post/149/
Something like this should do what you need:
<fb:like href="http://www.google.com"></fb:like>
<!-- Like button to whatever object you want^^ -->
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"
type="text/javascript" charset="utf-8"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"
type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
FB.init({
appId: 'APP_ID',
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('edge.create', function(href)
{
// href is the URL of the object that got liked
// do whatever magic ajax you want
});
</script>
I use this code
<fb:login-button autologoutlink="true" perms="user_likes" size="large"></fb:login-button>
to create a login/logout fb button.
Everything works, after the login, the login button become a logout button. But If the user click on the logout button, the current page is not refreshed and so all the things that should appear only when the user is authenticated are still there until a manual page refresh is done.
This doesn't happen if I get the logout url (Javascript SDK)
$logoutUrl = $facebook->getLogoutUrl();
and then implement a logout button myself; in that case a proper "next" parameter (with the url of the current page) is passed and the current page is reloaded.
I still would like to use the first solution, is it possible to make it use the "next" parameter?
Do the redirect yourself - add this to JavaScript, somewhere after FB.init():
<script>
FB.Event.subscribe("auth.logout", function() {window.location = '/logout'});
</script>
This function will fire when logout through the FB button happens.
For integrated authentication (Facebook + Asp.Net MVC), I just use Javascript and FormsAuthentication.SignOut();
function LogoutFacebook() {
FB.logout(function (response) {
window.location = "/facebook/logout/";
}); }
Above answer by Piskvor did it for me. Its crazy how many hours I've spend trying to figure this out.
Main problem with plugins such as this Facebook for CakePHP is that they don't come with updates. APIs, especially popular ones like Facebook, change all the time because they are being imporved. If the guy who wrote it initially as a hobby moves on with his life and stops updating the SDK people who are less knowladgable on how to alter these things become stuck.
WORKING CODE:
Nevertheless, thanks for a great solution Piskvor, here is my piece of code for
apps/plugins/facebook/views/helpers/facebook.php
$init .= $this->Html->scriptBlock(
<<<JS
window.fbAsyncInit = function() {
FB.init({
appId : '{$appId}',
session : {$session}, // don't refetch the session when PHP already has it
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.logout", function() {
window.location = '/users/logout'
});
{$callback}
};
The key piece of code here is:
FB.Event.subscribe("auth.logout", function() {
window.location = '/users/logout'
});
{$callback}
I integrated the graph api facebook connect but if we are login to facebook, we will automatically login to the site with facebook connect as well. Is there any way we let the user clicks on fb "Login" only then the user is connected to the site with their fb account?
Now the user is automatically login to the site without the option to choose whether they would want to use their facebook account. If they want to logout from the site, they need to logout from facebook completely only then they can logout from the site with facebook connect as well.
Anyone can help me or give some tips how to go about?
Thank you!
I had this same problem on a recent website, and found a way to overcome it. My solution allowed a user to already be logged into facebook on their computer, yet not have it auto login on my website, then they can login with Facebook Login button and finally when they logout it won't log them out of Facebook on their computer, just on my website (much like Digg does with facebook).
To do it I was using https://github.com/facebook/php-sdk/ to check within PHP if there was an active facebook session with the user and the website (which would cause the auto login). If there was, I would not echo the auto login code:
FB.init({
appId : '<?php echo $facebook->getAppId(); ?>',
session : <?php echo json_encode($session); ?>, // don't refetch the session when PHP already has it
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.login', function() {
window.location = "process-login.php";
});
but instead just render my own facebook login button that would link to "process-login.php".
process-login.php would set the custom $_SESSION variable that told my website someone was logged (whether via my own system, or via facebook), and then reload the referring page (using $_SERVER['HTTP_REFERER']) which would now display the user as logged in via Facebook since my own $_SESSION variable was now set. To log them out (without logging them out of Facebook entirely, just my website), I would just load a logout script that removed the $_SESSION variable.
The example.php (in the php-sdk on github) was very helpful at finding my solution, though I had to customise it significantly to make it work with my existing system. It at least helped me see how to access the facebook session variable in PHP (stored in $me in the example).
Hope this helps you if its still a problem, or that it helps someone else in this situation.
EDIT:
Turns out I still had some issues with auto login on the rare occasion. To fix it I removed the event.subscribe('auth.login') and make a facebook button that called the following function to check login status before subscribing to the auth.login even. Here is the function:
function check_login_session(){
FB.getLoginStatus(function(r){
if(r.session){
window.location = '/process-login.php';
}
else{
FB.Event.subscribe('auth.login', function(response) {
window.location = '/process-login.php';
});
FB.login();
}
});
}`
I had the same problem, I guess that you are using the scripts provided by facebook. In that case you have a function associated with the window.fbAsyncInit event. This happens everytime that the page is loaded.
At the end of this method you have the code:
FB.getLoginStatus(function(response) {
statusChangeCallback(response);
});
The function statusChangeCallback verifies your user's facebook status (connected, authorized, or unknown). Here, if the user is "connected" you log him into your site. Well that's the problem, you are always trying to log the user in with facebook.
This must only happen on click, so you should erase those lines
hello dear I think you have made your question so confused. Your question is not stating what actually do you want. As for as I have understood I think you want to connect the user to you site through facebook connect and you want when user clicks on facebook logout, it automatically logouts from your site.
if my understanding about your question is right then simply let the user to login through facebook and do logins in your system in FB.Event.Subscribe event.
Use the following code for login button
<fb:login-button perms='email' autologoutlink='true'>
When user will allow your his facebook account to connect with your site
<div id="fb-root">
<script>
window.fbAsyncInit = function() {
FB.init({appId: "Your APP ID",
status: true,
cookie: true,
xfbml: true});
FB.getLoginStatus(function(response) {
if (response.session) {
// Send here parameters that logins to your system through your website login system
} else {
}
});
FB.Event.subscribe("auth.login", function(response) {
window.location.reload();
});
FB.Event.subscribe("auth.logout", function(response) {
window.location.reload();
//Send the Parameters that logouts user from your website through your website logout system;
});
};
(function() {
var e = document.createElement("script");
e.type = "text/javascript";
e.src = document.location.protocol +
"//connect.facebook.net/en_US/all.js";
e.async = true;
document.getElementById("fb-root").appendChild(e);
}());
and put the above whole code right after your <body> tag
If You have:
FB.Event.subscribe('auth.login', function() {
fbLogin(this);
});
Try to comment it /* fb.Event..... */