Integrarare il Login di Facebook nel Cloud Titanium


/ Published in: JavaScript
Save to your folder(s)

Utilizzare il login d facebook in icloud appcelerator


Copy this code and paste it in your HTML
  1. var Cloud = require('ti.cloud');
  2. Titanium.Facebook.appid = "285243484913611";//Production
  3. Titanium.Facebook.permissions = ['publish_stream', 'read_stream'];
  4.  
  5. var win = Ti.UI.createWindow({
  6. title : "ACS Social Integrations"
  7. });
  8.  
  9. var fbSignupBtn = Ti.UI.createButton({
  10. title : "Login with Facebook",
  11. width : 160,
  12. top : 50
  13. });
  14. win.add(fbSignupBtn);
  15.  
  16. fbSignupBtn.addEventListener('click', function() {
  17. if (!Titanium.Facebook.loggedIn) {
  18. Titanium.Facebook.authorize();
  19. }
  20. });
  21.  
  22. //add SocialIntegrations in Facebook login event listener
  23. Titanium.Facebook.addEventListener('login', function(e) {
  24. if (e.success) {
  25. alert("login Success ");
  26. //code for SocialIntegrations
  27. } else if (e.error) {
  28. alert("Error = " + e.error);
  29. } else if (e.cancelled) {
  30. alert("Canceld");
  31. }
  32. });
  33.  
  34. win.open();
  35.  
  36.  
  37.  
  38. ///
  39. STEP2
  40.  
  41. Titanium.Facebook.addEventListener('login', function(e) {
  42. if (e.success) {
  43. Cloud.SocialIntegrations.externalAccountLogin({
  44. type : 'facebook',
  45. token : Ti.Facebook.accessToken
  46. }, function(e) {
  47. if (e.success) {
  48. var user = e.users[0];
  49. Ti.API.info('User = ' + JSON.stringify(user));
  50. Ti.App.Properties.setString('currentUserId', user.id);
  51. alert('Success: ' + 'id: ' + user.id + '\\n' + 'first name: ' + user.first_name + '\\n' + 'last name: ' + user.last_name);
  52. } else {
  53. alert('Error: ' + ((e.error && e.message) || JSON.stringify(e)));
  54. }
  55. });
  56. } else if (e.error) {
  57. alert("Error = " + e.error);
  58. } else if (e.cancelled) {
  59. alert("canceld");
  60. }
  61. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.