2012-03-23 19 views
0

我对钛手机很熟悉,现在我正在开发iOS应用程序。在钛手机上的Facebook自定义登录

我想创建自定义登录按钮。 我按照网上的一些说明,但仍然无法正常工作。 代码如下。

var win = Ti.UI.currentWindow; 
Titanium.Facebook.appid = "APP ID"; 
Titanium.Facebook.permissions = ['permissions here']; 

var login = Ti.UI.createButton({ 
    backgroundImage:'facebooklogin.png', 
    width:250, 
    height40: 
}); 

win.add(login); 

login.addEventListener('click', function(e) { 
    Titanium.Facebook.authorize(); 
}); 

Titanium.Facebook.addEventListener('login', function(e) { 
     if (e.success) { 
      Titanium.Facebook.requestWithGraphPath('me', {}, 'GET', function(e) { 
       if (e.success) { 
        var data= JSON.parse(e.result); 
        Ti.API.info("Name:"+data.name); 
        Ti.API.info("email:"+data.email); 
        Ti.API.info("facebook Id:"+data.id); 
       } else if (e.error) { 
        alert(e.error); 
       } else { 
        alert('Unknown response.'); 
       } 
      }); 
     }else{ 
      if(e.error){ 
       alert(e.error); 
      }else{ 
       alert("Unkown error while trying to login to facebook."); 
      } 
     } 
    }); 
} 

有没有人给我看解决方案?

谢谢。

+0

你得到的错误是什么? – DannyM 2012-03-23 16:09:52

+0

哦,是的,我忘了写它。 单击按钮,然后没有任何反应。我期待的是关于Facebook登录的模式窗口,出现,但.... – user1258134 2012-03-23 19:35:50

回答

0

如果您已经授权Ti.Facebook.authorize方法不会做任何事情。尝试清除设备中的应用数据,然后重新开始。