2012-09-26 81 views
4

我正在使用(Appcelerator)钛的Facebook API让用户登录到他们的Facebook帐户。在Android后常权当调用Facebook的窗口中打开一个页面显示它说授权:钛 - Facebook授权() - “发生错误”

An error occurred with MY-FB-APP-NAME. Please try later 
API Error Code: 110 
API Error Description: Invalid user id 
Error Message: Missing user cookie (to validate session user) 

关闭窗口,并重新开始通常可以解决该问题。然而,当这种情况发生时,可能有70%的时间(第一次在“会话”中调用授权时),这是一个很大的可用性问题。

有谁知道如何解决这个问题?

我正在使用Titanium 2.1.0并在Android 2.3.6设备上进行测试。 非常感谢

+0

我收到了同样的问题。你是否已经在控制台中使用** Ti.API.info(response)**修复了这个 – glo

回答

0

实际上由于Facebook的缓存存在问题。我们需要清除缓存,当您退出使用下面的代码,它工作正常

Titanium.Facebook.appid = "XXXXXXXXXXXXXXXXXX"; 
Titanium.Facebook.permissions = ['publish_stream', 'read_stream']; 


    var fbButton = Ti.UI.createButton({ 
    top: 68, 
    width:290, 
    height:52, 
    backgroundImage:"images/login/facebook.png" 
}); 


fbButton.addEventListener('click', function() { 
if(Titanium.Facebook.loggedIn){ 
    Titanium.Facebook.logout() 
    return 
} 
Titanium.Facebook.authorize(); 

    }); 




Ti.Facebook.addEventListener('login', function(e) { 
if (e.success) { 
    win.close() 
} else if (e.error) { 
    alert(e.error); 
} else if (e.cancelled) { 
    alert("Canceled"); 
} 
}); 

    Titanium.Facebook.addEventListener('logout', function(e) { 
    var url = 'https://login.facebook.com'; 
    var client = Titanium.Network.createHTTPClient(); 
    client.clearCookies(url); 
}); 
0

试试这个代码,其合金,并希望它会帮助你,否则我会检查,让你知道

指数.XML

<Alloy> 
<Window class="container"> 
    <LoginButton id="fbButton" ns="Alloy.Globals.Facebook"/> 
</Window> 
</Alloy> 

index.js

var fb = Alloy.Globals.Facebook; 
fb.appid = xxxxxxxxx; 
fb.permissions = ['publish_stream', 'create_event', 'email']; 
$.fbButton.style = fb.BUTTON_STYLE_WIDE; 
fb.addEventListener('login', function(e){ 
    if(e.success){ 
     fb.requestWithGraphPath('me', {}, 'GET', function(e) { 
      if (e.success) { 
       //alert(e.result); 
       var response = JSON.parse(e.result); 
       var email = response.email; 
       var name = response.name; 
       var gender = response.gender; 
       alert(name+' '+email+' '+gender); 
       alert('Logged in Successfully'); 
      } else if (e.error) { 
       alert(e.error); 
      } else { 
       alert('Unknown response'); 
      } 
     }); 
    } 
}); 

alloy.js

Alloy.Globals.Facebook = require('facebook'); 
+0

打印,并且查看你的应用程序从Facebook获取和使用它所需的全部内容。 – Guts