Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //index.js
- var fb = require('com.ti.facebook');
- function doClick(e)
- {
- if (!fb.loggedIn)
- Ti.API.log('not logged in')
- else
- Ti.API.log('logged in')
- fb.permissions = ['public_profile', 'email', 'user_friends'];
- fb.addEventListener('login', function(e) {
- if(e.success) {
- Ti.API.log('login successful!!')
- } else if (e.cancelled) {
- Ti.API.log('cancelled')
- } else if (e.error) {
- if (Ti.Platform.name === 'iPhone OS') {
- var loginAlert = Ti.UI.createAlertDialog({title: 'Login Error'});
- if (e.error.indexOf('OTHER:') !== 0){
- } else {
- Ti.API.log('error else')
- }
- } else {
- Ti.API.log('error else')
- }
- } else {
- Ti.API.log('other error...')
- }
- });
- fb.initialize(0);
- var win = Ti.UI.createWindow();
- win.fbProxy = fb.createActivityWorker({lifecycleContainer: win })
- var btn = Ti.UI.createButton({ Title : 'facebook login' });
- btn.addEventListener('click', function(e)
- {
- Ti.API.log('facebook login clicked')
- fb.authorize();
- })
- win.add(btn);
- win.open();
- }
- $.win.open();
- <!-- index.xml -->
- <Alloy>
- <Window class="container">
- <Label id="label" onClick="doClick">Facebook Login</Label>
- </Window>
- </Alloy>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement