FB not defined Error on implementing Facebook logout in Django app - javascript

I was trying to implement facebook logout functionality for my django app. In my app, users can log in using app username or with FB username. Now i want to implement logout functionality also.
For doing that i put this code in my html page, but i am getting 'FB is not defined' error. Can somebody help me to solve this ?
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'xxx',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
<script>
function logout(){
FB.getLoginStatus(handleFBSessionResponse);
location.href = '/user_sessions/new';
}
// handle a session response from any of the auth related calls
function handleFBSessionResponse(response) {
/*
//Check the facebook login status
alert("handleFBSessionResponse(), "
+ "\nresponse.status="+response.status
+" \nresponse.session="+response.session
+" \nresponse.perms="+response.perms);
*/
//if we do have a non-null response.session, call FB.logout(),
//the JS method will log the user out
//of Facebook and remove any authorization cookies
FB.logout(handleFBSessionResponse);
}
</script>
<a href="javascript:logout();">Logout</a >

i got it working with this
<a href="http://m.facebook.com/logout.php?confirm=1&next=http://10.1.0.90:8080/registrationForm" >Sign Out</a>

Related

Meteor: create user account when the client is authenticated the fist time they signin with linkedin?

I am running meteor.js and have globally installed npm package node-linkedin
https://www.npmjs.com/package/node-linkedin
I have registered my application with linkedin which means I have my api key, secret key and oAuth redirect urls to localhost:3000
My app currently displays the 'sign in' linkedIn button where the user grants my application access to the full profile of the user. According to linkedIn javascript API docs, the onLinkedInAuth() object (which runs upon successful authentication) contains the linkedin id of the user.
How do I create a user account, Accounts.createUser when the user is authenticated and store the id from the onLinkedInAuth() object in the user collection?
server.js
var Linkedin = Npm.require('node-linkedin')('api', 'secret', 'I-PUT-REDIRECT-URL-HERE');
How do I make the get requests using the npm package https://www.npmjs.com/package/node-linkedin (see under heading oAuth 2.0) which redirects the user to linkedins authorization dialog and subsequently retrieve the access token.
HTML:
<head>
<script type="text/javascript" src="https://platform.linkedin.com/in.js">
api_key: *MY_API_KEY*
onLoad: onLinkedInLoad
authorize: true
</script>
<script type="text/javascript">
// Runs when the JavaScript framework is loaded
function onLinkedInLoad() {
IN.Event.on(IN, "auth", onLinkedInAuth);
}
// Runs when the viewer has authenticated
function onLinkedInAuth() {
IN.API.Profile("me")
.result( function(me) {
var id = me.values[0].id;
// AJAX call to pass back id to your server
});
}
// Runs when the Profile() API call returns successfully
function displayProfiles(profiles) {
member = profiles.values[0];
document.getElementById("profiles").innerHTML =
"<p id=\"" + member.id + "\">Hello " + member.firstName + " " + member.lastName + "</p>";
}
</script>
</head>
<template name="parent"> //layout template
<!-- Displays a button to let the viewer authenticate -->
<script type="IN/Login" data-onAuth="onLinkedInAuth"></script>
<!-- Placeholder for the greeting -->
<div id="profiles"></div>
</template>
Have you considered using a combination of https://github.com/Differential/accounts-entry and https://atmospherejs.com/pauli/accounts-linkedin? Based on the docs for http://docs.meteor.com/#/full/accounts_oncreateuser, you should be able to fetch the data from options.profile.

Facebook jQuery Logout using Logout URL and Access Token

When a user logs out of my site, unless they also log out of their Facebook account, they remain logged in to my site.
I'd like to comply with point 6 of this policy, so how can I log my users out of my site and out of their Facebook accounts for security https://developers.facebook.com/policy/
I have the following code bound to my login button and it's not working - the user is still logged in to FB after clicking. My console shows that the var accessToken is not defined but I'm not sure why. I'm sure I'm doing something fundamentally wrong, would really appreciate some help!
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".logout").click(function () {
FB.init({appId : <?php echo $this->config->item('facebook_appid');?>,
status : true,
cookie : true,
oauth : true,
frictionlessRequests: true});
FB.login(function(response) {
if (response.authResponse) {
console.log(response.authResponse.accessToken);
var accessToken = response.authResponse.accessToken;
}
});
window.location.replace("https://www.facebook.com/logout.php?confirm=1&next=http://www.mysite.com&access_token="+accessToken+"");
});
});
</script>
<div id="fb-root"></div>
To log out of Facebook, you need to use the FB.logout() method.
If you have already called the FB.init() and the FB.login() methods, you don't need to call these again in your click function.

Unable to get login status from facebook

I am new to facebook app development. I am trying to get access token from the facebook. For that, I am trying to check my login status using the following code
<html>
<body>
<fb:login-button></fb:login-button>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({appId: 'appId', status: true, cookie: true, xfbml: true});
alert('page 1');
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
alert('Page 2');
// connected
} else if (response.status === 'not_authorized') {
// not_authorized
} else {
// not_logged_in
}
});
}
</script>
</body>
</html>
When i executes the above code, it shows a login button where i can login sucessfully. I can get 'Page 1' alert but I cannot get 'Page 2' alert. I dont know what's wrong with this code.
Thanks.
Check if you have enabled Sanbox mode in your application. If yes, and if you're not currently logged in as a user that has admin or developer role for this application, this will happen. Try if it'll work after disabling Sandbox for a while. Check answer to this question - https://stackoverflow.com/a/8485361/1816426
Of course I'm assuming, that appId: 'appId' part is an example only and you have correct application ID in your code taken from application's settings.
A few tips to get you going:
1) Check if your appID is valid (I'm hoping you didn't literally write appId, and have actually inserted an appID which you registered)
FB.init({appId: 'appId', status: true, cookie: true, xfbml: true});
2) try looking at the actual response by doing:
alert(response);
*The details of the response are stated here: https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
But my guess is that your application isn't registered correctly, or that you haven't inserted a correct appID in your appID field. That is usually the case.

FB.login is always asking my password (even if I'm already logged in)

I'm playing with Facebook Javascript SDK in order to implement a Facebook Connect action. It's already working but the problem is that every time that I try to login again on my application the user has to reenter its facebook password.
I'm sure that there is an option to do this step without entering the password if you are already logged in in facebook (I have seen this in lots of web pages). But how? The documentation http://developers.facebook.com/docs/reference/javascript/FB.login/ and even the source code does not explain how to do this:
"#param opts {Object} (optional) Options to modify login behavior."
My implementation right now is like this:
function login(){
FB.login(function(response) {
if (response.authResponse) {
$(".fb_login").hide();
$(".fb_logout").show();
FB.api('/me', function(response) {
register_user(response.id, response.name);
});
} else {
alert('User cancelled login or did not fully authorize.');
}
});
}
And I call to FB.init like this:
FB.init({
appId : 'xxxxxxxxx', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
Maybe it has to be a change in the FB.init or some kind of option while calling to FB.login. Any ideas?
Thanks in advance,
Raimon Bosch.
There is a method FB.getLoginStatus which you can use to check if user is already loggedin:
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
var accessToken = response.authResponse.accessToken;
//you are loggedin
} else if (response.status === 'not_authorized') {
//loggedin but not authorized your app
} else {
// the user isn't logged in to Facebook.
}
});
Did you mean something like that
Check the
Force Web OAuth Reauthentication in your PP setting facebbok developer>Your App> facebook login > setting > set Force Web OAuth Reauthentication to NO

How to check liked fan page from iframe apps via Graph API and Javascript-SDK

Here is my code, this is working fine only on apps developer account. WT is my wrong?
window.fbAsyncInit = function() {
var APP_ID = 'XXXXX';
var PAGE_ID = 'XXXXX';
FB.init({
appId : APP_ID,
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
});
FB.api('/me/likes/' + PAGE_ID, function(response) {
t = $.toJSON(response);
alert(t);
});
}
RESULT
developer account:
{"data":[{"name":"111222333","category":"Small business","id":"281428705206834","created_time":"2011-09-02T14:14:37+0000"}]}
non-developer account:
{"error":{"type":"OAuthException","message":"An active access token must be used to query information about the current user."}}
It might have something to do with the page settings. If the page is set to be invisible, as in only visible for the administrators of that page, that could be a cause why you are getting that error.
Have you set your page available for everyone?
In order to see a user likes with graph api you will need the permissions to do so. user_likes
See: http://developers.facebook.com/docs/reference/api/permissions/

Categories

Resources