Skip to content

Instantly share code, notes, and snippets.

@addieljuarez
Last active December 27, 2015 20:59
Show Gist options
  • Select an option

  • Save addieljuarez/7388206 to your computer and use it in GitHub Desktop.

Select an option

Save addieljuarez/7388206 to your computer and use it in GitHub Desktop.
FacebookTaller
var win = Titanium.UI.createWindow({
backgroundColor:'#000',
});
var fb = require('facebook');
var email = Titanium.UI.createLabel({
top:5,
color:'#fff',
});
var nombre = Titanium.UI.createLabel({
top:20,
color:'#fff',
});
var id = Titanium.UI.createLabel({
top:35,
color:'#fff'
});
var foto = Titanium.UI.createImageView({
top:55,
height:80,
width:80,
borderRadius:10,
borderColor:'#fff',
borderWidth:4,
});
function LoginFacebook(){
fb.appid = '';
fb.permissions = ['email, user_birthday, user_hometown, user_location, publish_actions, publish_stream, publish_checkins, user_photos']; // Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(e) {
if (e.success) {
// alert('Logged In');
fb.requestWithGraphPath('me', {}, 'GET', function(e) {
if (e.success) {
// alert(e.result);
var prueba = JSON.parse(e.result);
// alert(prueba);
// alert(prueba.email);
email.text = prueba.email;
nombre.text = prueba.first_name;
id.text = prueba.id;
foto.image = 'https://graph.facebook.com/'+prueba.id+'/picture';
} else if (e.error) {
alert(e.error);
} else {
alert('Unknown response');
}
});
} else if (e.error) {
alert(e.error);
} else if (e.cancelled) {
alert("Canceled");
}
});
fb.authorize();
};
function LogOutFacebook(){
fb.logout();
fb.addEventListener('logout', function(e) {
alert('Logged out');
});
};
var boton = Titanium.UI.createButton({
// title:'login',
height:40,
width:150,
backgroundImage:'images/conecface.png'
});
var boton2 = Titanium.UI.createButton({
bottom:100,
height:40,
width:150,
title:'logout',
});
boton.addEventListener('click', LoginFacebook);
boton2.addEventListener('singletap', LogOutFacebook);
win.add(boton);
win.add(boton2);
win.add(email);
win.add(id);
win.add(nombre);
win.add(foto);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment