Mootools login facebook - javascript

In a simple webpage I want user to be able to login with his facebook acount which is in javascript and mootools framework. The code is:
var moofb = new MooFB.Base(APP_ID);
$('login').addEvent('click', function() {
moofb = new MooFB.Base(371204703259599);
moofb.login(function(response) {
if(response.session) {
console.log('ifNr1');
if(response.perms) {
console.log(response);
}
}
console.log('User cancelled login or did not fully authorize.');
}.bind(moofb));
});
$('perms').addEvent('click', function() {
moofb.login(function(response) {
if(response.session) {
if(response.perms) {
}
}
}.bind(moofb), {perms: 'read_stream,publish_stream'});
});
But login does not work. May I know where the problem is?
Edit: As stated in the duplicate question, there is an error MooFB.Base is not a constructor.

If you did not include the two dependencies listed :
Core/Class
Core/Object
This is why you get the error MooFB.Base is not a constructor.

Related

GoogleAuth.signOut() does not work

I have a google sign-in button on my page, using gapi.signin2.render to render the button (https://developers.google.com/identity/sign-in/web/reference#gapisignin2renderid-options).
However it ALWAYS renders as signed-in, despite calling GoogleAuth.signOut(). In fact I can actually call GoogleAuth.signOut() and immediatly check GoogleAuth.isSignedIn.get() to check the state and returns as true.
Does anyone know how to fix this? My sign-out code is as follows:
var GoogleAuth = gapi.auth2.getAuthInstance();
GoogleAuth.signOut().then(() => {
var status = GoogleAuth.isSignedIn.get(); //ALWAYS TRUE!!!!
alert('IP.common.oAuth.signOut: signin status: ' + status);
});
This should be work fine. Delete then(this.props.onLogoutSuccess)) if you don't need it.
signOut() {
if (window.gapi) {
const auth2 = window.gapi.auth2.getAuthInstance()
if (auth2 != null) {
auth2.signOut().then(auth2.disconnect().then(this.props.onLogoutSuccess))
}
}
}
Very nice lib, if you wanna learn how to work with Google API https://github.com/anthonyjgrove/react-google-login. Yes it's react, but methods should be similar, I think.

LinkedIn Javascript SDK Fail To Return Positions

I am trying to use LinkedIn Javascript SDK to retrieve some information including positions fields. I copied the code from the internet but it seems something is not working quite right because the code i copied doesn't return positions fields as supposed to be. I tried on ApiGee it worked fine and it returned the list of positions as i am expected. If you look at the code below , do you think i missed something or the javascript SDK itself has some buggy problems ?
<script type="text/javascript" src="//platform.linkedin.com/in.js">
api_key: yourapikey
authorize: true
onLoad: onLoad
</script>
<script type="text/javascript">
function onLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
// Handle the successful return from the API call
function onSuccess(data) {
alert(JSON.stringify(data));
}
// Handle an error response from the API call
function onError(error) {
console.log(error);
}
// Use the API call wrapper to share content on LinkedIn
function getProfileData() {
//alert(IN.ENV.auth.oauth_token);
IN.API.Raw("/people/~:(id,positions)?format=json").result(onSuccess).error(onError);
}
</script>
Return result is showing this :
{"id":"wQplQQjzLa","positions":{"_total":0}}
Hello there #John Hadikusumo,
Well, I do understand that this reply would be happening only a year later but, I too was facing some problems with the linkedin api integration especially when it came to the "positions" object values.
Apparently when I got an error, what it meant was that the user who is using his linkedin profile to authorize, that particular user has not initiated his experience details and thus has no value;
To circumvent this particular problem here is what I had done which had helped me:
function onLinkedInLoad() {
IN.Event.on(IN, "auth", getProfileData);
}
function onSuccess(data) {
console.log(data);
}
function onError(error) {
console.log(error);
}
function getProfileData(){
IN.API.Profile("me").fields(["firstName","lastName", "email-address", "positions"]).result(function(data) {
var profileData = data.values[0];
var profileFName = profileData.firstName;
var profileLName = profileData.lastName;
//this is the piece of code that helped me out;
//might work for you as well;
if(data.values[0].positions._total == "0" || data.values[0].positions._total == 0 || data.values[0].positions._total == undefined) {
console.log("Error on position details");
var profileCName = "Details Are Undefined";
}
else {
var profileCName = profileData.positions.values["0"].company.name;
}
var profileEName = profileData.emailAddress;
//and other logic/code continues...
});
}
So I do hope this helps you out. Do let me know if you had faced any other errors, I could use some help in case I would need to improve my existing code.
Cheers and Have a nice day.

Detect closing the "Request for Permission" window (Google Account login)

I'm implementing a Google Account login on my website and I've reached the following problem: when the user chooses to login using his/her Google Account, Google's Request for Permission popup window opens and, if the user closes it, I have no way of detecting this in any way.
Here's the relevant code, using GoogleAuth.attachClickHandler method:
gapi.load('auth2', function() {
var auth2 = gapi.auth2.init({
client_id: 'my-client-id.apps.googleusercontent.com',
cookiepolicy: 'single_host_origin',
});
auth2.attachClickHandler(button, {},
function(googleUser) {
successHandler(googleUser);
}, function(error) {
failureHandler(error);
});
});
If the user presses Accept, successHandler is called and if the user presses Cancel, failureHanlder is called. However, if the user simply closes this window, nothing happens and my website keeps waiting for some callback.
Is there any way to detect this, other than adding a timeout?
So, I guess I came up with a (very ugly) solution. Answers are still welcome, if someone knows of a better way.
Basically, I replace the default window.open function with my own and monitor if a Google window opens and then periodically check if it closed:
Function.prototype.isNative = function() {
return this.toString().indexOf('[native code]') > -1;
}
function registerGoogleTimeoutCallback() {
if (window.open.isNative()) {
var originalOpen = window.open;
window.open = function(URL, name, specs, replace) {
var newWindow = originalOpen(URL, name, specs, replace);
if (URL.indexOf('https://accounts.google.com/') === 0) {
var interval = setInterval(function() {
if (newWindow.closed) {
clearInterval(interval);
setTimeout(function() {
$(window).trigger('googleWindowClosed');
}, 2000);
}
}, 1000);
}
return newWindow;
}
} else {
throw 'window.open already replaced'
}
}
This way, I use $(window).on('googleWindowClosed', callback) to register a failure callback and also $(window).off('googleWindowClosed') to unregister it, in case of success.

FB SDK Version 2.4 not returning value for /me/groups

I am trying to get the User's groups list with the following code:
$(document).ready(function() {
$("#fetchButton").click(function() {
console.log('fetch button');
FB.getLoginStatus(function(res){
if( res.status == "connected" ){ // check if logged in
// get user data first, which will be handled by an anonymours fucntion passed inline
FB.api('/me', function(meResponse) {
//console.log(meResponse);
UID = meResponse.id;
getGroups();
console.log(meResponse);
});
} else { // if not logged in, call login procedure
FB.login(function(){
$("#fetchButton").click();
}, {scope: 'publish_actions, publish_actions, read_stream, user_groups'});
}
});
});
});
function getGroups() {
FB.api('/me/groups', function(groupResponse) {
console.log(groupResponse);
});
}
This code used to work with some old version of FB SDK. But not now.
Any help!
read_stream and user_groups are deprecated and you are using publish_actions two times. In order to get a list of all the groups you manage, you need to use user_managed_groups now.
More information: https://developers.facebook.com/docs/apps/changelog#v2_4

Read Meteor Session on a different page

I want to display a "Welcome back" message on the home page after the user performs a successful signIn. However, after I make a redirect with Router.go('home');, I can't read the Session within my Template.home.rendered = function().
Here is my code:
Login logic:
Meteor.loginWithPassword(username, password, function(err) {
if (err) {
showError();
} else {
Session.set('signInSuccess', true);
Router.go('home');
}
});
Template.home.rendered = function() {
console.log(Session.get('signInSuccess'));
if (Session.get('signInSuccess') == true) {
showWelcomeMessage();
Session.set('signInSuccess', null);
}
}
Any help would be greatly appreciated.
This is simply because Template.home.rendered is executed exactly once when your template is first inserted in the DOM (it may get executed again if the template is destroyed and reinserted, via the routing mechanism).
See rendered behavior here : http://docs.meteor.com/#template_rendered
Try wrapping your verification code inside an autorun :
Template.home.rendered=function(){
// setup a reactive computation to watch for Session variable modification
this.autorun(functon(){
// using Session.equals is better than checking against Session.get
// see http://docs.meteor.com/#session_equals
if(Session.equals("signInSuccess",true)){
showWelcomeMessage();
Session.set("signInSuccess",false);
}
});
};

Categories