4

I am using (Appcelerator) Titanium's Facebook API to let users log in to their facebook accounts. On Android often right after calling authorize when the facebook window opens a page is shown which says:

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)

Closing the window and starting over usually resolves the problem. However as this happens maybe 70 % of the time (when calling authorize for the first time in a "session") it is a big usability issue.

Does anyone know how to fix this?

I'm using Titanium 2.1.0 and testing on an Android 2.3.6 device. Thanks a lot

2 Answers2

0

Actually the problem persist due to cache of facebook . we need to clear cache when you log out use below code it works fine

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);
});
sundar nataraj
  • 8,524
  • 2
  • 34
  • 46
0

Try this code, its in alloys and hope it will help you, else I will check and let you know

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');
Guts
  • 81
  • 4
  • 20
  • Print using **Ti.API.info(response)** in console and see what and all you required for your application from facebook and fetch and use it. – Guts Oct 01 '13 at 07:36