/ Published in: JavaScript
Utilizzare il login d facebook in icloud appcelerator
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var Cloud = require('ti.cloud'); Titanium.Facebook.appid = "285243484913611";//Production Titanium.Facebook.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 (!Titanium.Facebook.loggedIn) { Titanium.Facebook.authorize(); } }); //add SocialIntegrations in Facebook login event listener Titanium.Facebook.addEventListener('login', function(e) { if (e.success) { alert("login Success "); //code for SocialIntegrations } else if (e.error) { alert("Error = " + e.error); } else if (e.cancelled) { alert("Canceld"); } }); win.open(); /// STEP2 Titanium.Facebook.addEventListener('login', function(e) { if (e.success) { Cloud.SocialIntegrations.externalAccountLogin({ type : 'facebook', token : Ti.Facebook.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"); } });