Skip to content

Instantly share code, notes, and snippets.

@rajubd49
Created April 16, 2015 07:49
Show Gist options
  • Save rajubd49/c4b4aac32182ab9b0b15 to your computer and use it in GitHub Desktop.
Save rajubd49/c4b4aac32182ab9b0b15 to your computer and use it in GitHub Desktop.
ACS External Login - Appcelerator Titanium
var Cloud = require('ti.cloud');
var fb = require('facebook');
fb.appid = "appid";
fb.permissions = ['publish_stream', 'read_stream'];
var win = Ti.UI.createWindow({
title : "ACS Social Integrations"
});
var fbSignupBtn = Ti.UI.createButton({
title : "Login with Facebook",
width : 160,
top : 50
});
win.add(fbSignupBtn);
fbSignupBtn.addEventListener('click', function() {
if (!fb.loggedIn) {
fb.authorize();
}
});
fb.addEventListener('login', function(e) {
if (e.success) {
Cloud.SocialIntegrations.externalAccountLogin({
type : 'facebook',
token : fb.accessToken
}, function(e) {
if (e.success) {
var user = e.users[0];
Ti.API.info('User = ' + JSON.stringify(user));
Ti.App.Properties.setString('currentUserId', user.id);
alert('Success: ' + 'id: ' + user.id + '\\n' + 'first name: ' + user.first_name + '\\n' + 'last name: ' + user.last_name);
} else {
alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
}
});
} else if (e.error) {
alert("Error = " + e.error);
} else if (e.cancelled) {
alert("canceld");
}
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment