【问题标题】:Titanium - Facebook authorize() - "An error occurred"Titanium - Facebook 授权() - “发生错误”
【发布时间】:2012-09-18 06:34:26
【问题描述】:

我正在使用 (Appcelerator) Titanium 的 Facebook API 让用户登录到他们的 Facebook 帐户。在 Android 上,当 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 设备上进行测试。 非常感谢

【问题讨论】:

  • 我遇到了同样的问题。你解决了吗

标签: javascript facebook login titanium titanium-mobile


【解决方案1】:

试试这个代码,它是合金的,希望它能帮助你,否则我会检查并告诉你

index.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');

【讨论】:

  • 在控制台中使用 Ti.API.info(response) 打印,然后从 facebook 中查看您的应用程序所需的内容和所有内容,然后获取并使用它。
【解决方案2】:

实际上,由于 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);
});

【讨论】:

    猜你喜欢
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    • 2017-09-20
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多