Skip to content

Instantly share code, notes, and snippets.

@mauropm
Created July 6, 2013 16:28
Show Gist options
  • Save mauropm/5940389 to your computer and use it in GitHub Desktop.
Save mauropm/5940389 to your computer and use it in GitHub Desktop.
Example about how to connect to facebook, syncing the fb username with your ACS Cloud, and looking for your friends using the same app. USAGE: Create a new mobile project, classic titanium, with cloud support. Paste this app.js into your project's app.js.
var Cloud = require('ti.cloud');
Cloud.debug = true;
// optional; if you add this line, set it to false for production
var fb = require('facebook');
// Check for your app id in developers.facebook.com
fb.appid = ADD_YOUR_APPID_HERE!;
fb.permissions = ['publish_stream'];
// Permissions your app needs
fb.forceDialogAuth = true;
fb.addEventListener('login', function(e) {
if (e.success) {
alert('Logged In');
Cloud.SocialIntegrations.externalAccountLogin({
type : 'facebook',
token : Ti.Facebook.accessToken
}, function(e) {
if (e.success) {
var user = e.users[0];
alert('Success:\n' + 'id: ' + user.id + '\n' + 'first name: ' + user.first_name + '\n' + 'last name: ' + user.last_name);
Cloud.SocialIntegrations.searchFacebookFriends(function(e) {
if (e.success) {
alert('Success:\n' + 'Count: ' + e.users.length);
for (var i = 0; i < e.users.length; i++) {
var user = e.users[i];
alert('id: ' + user.id + '\n' + 'first name: ' + user.first_name + '\n' + 'last name: ' + user.last_name);
}
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
} else {
alert('Error:\n' + ((e.error && e.message) || JSON.stringify(e)));
}
});
} else if (e.error) {
alert(e.error);
} else if (e.cancelled) {
alert("Canceled");
}
});
fb.authorize();
var win = Ti.UI.createWindow({
backgroundColor : 'white',
});
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment