Skip to content

Instantly share code, notes, and snippets.

@atypical
Forked from aaronksaunders/kinvey_fb_snippet.js
Created March 26, 2014 21:35
Show Gist options
  • Save atypical/9794183 to your computer and use it in GitHub Desktop.
Save atypical/9794183 to your computer and use it in GitHub Desktop.
//
// http://devcenter.kinvey.com/titanium/
//
var Kinvey = require('kinvey-titanium-0.9.14');
// new appcelerator facebook module
var FB = require('facebook');
// my good friend momentjs
var moment = require('moment');
Kinvey.init({
appKey : 'appKey',
appSecret : 'appSecret'
});
//
// Facebook app id is set in the properties file
//
function doFacebookLoginAction(_authData) {
var authData = _authData || null;
if (FB.loggedIn) {
var expDate = moment(FB.expirationDate).format();
authData = {
"access_token" : FB.accessToken,
"expires_in" : expDate, //"2014-02-28T23:49:36.353Z"
};
} else {
var self = this;
FB.permissions = ["read_stream"];
FB.addEventListener("login", function(e) {
if (e.success) { debugger;
alert("Logged In");
doFacebookLoginAction();
} else if (e.error) {
alert(e.error);
Ti.API.info(' ERROR: ' + JSON.stringify(e, null, 2));
} else
e.cancelled && alert("Canceled");
});
FB.authorize();
return;
}
// attempt to log the user in using the FB information
// create a user
var user = new Kinvey.User();
// provide the auth data, and pass in any additional fields to
// to be added to the user object
user.loginWithFacebook(authData, {
"acct_email" : "[email protected]",
"acct_fname" : "Bryce",
"acct_lname" : "Saunders"
}, {
success : function() {
alert("Well done my friend!");
},
error : function() {
alert("Error code");
}
});
}
doFacebookLoginAction();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment