Domanda

I have built an app using titanium alloy

index.js

// Use the Alloy.Globals.Facebook namespace to make Facebook module API calls

var facebookModule = Alloy.Globals.Facebook;

//set facebook app id 

facebookModule.appid = Ti.App.Properties.getString("ti.facebook.appid");



//set permissions i.e what data I want

facebookModule.permissions = ['user_friends','user_photos'];



// Do not force a facebook html popover but use the native dialog if possible

facebookModule.forceDialogAuth = false;

//invoke method onto button from module

$.fbButton.style = facebookModule.BUTTON_STYLE_WIDE;


$.index.open();

In my index.js controller I have this segment of code, it executes and I am presented with a log in screen.

I then fall into 2 problems:

1) "FB Session: Should only be used from a single thread" 2) I am unable to get the access token.

Not sure how to resolve both as the inbuilt login function has it's own event handler.

Cheers

È stato utile?

Soluzione

Like you said, the inbuilt login function does have it's own handler.. so you should listen for event changes, something like this:

facebookModule.addEventListener('login', function(e) {
    if (e.success) {
       Ti.App.Properties.setString('face_token', facebookModule.getAccessToken());
       // DO SOMETHING WITH THE TOKEN - open new window, auth the user...
     }
});

If you try to get the access token BEFORE the login event is fired, you'll end up bad. Now about the single thread thing.. I did run into this a while back.. I'm not sure exactly what I did to solve it, but I think it might be related to opening multiple windows or event allowing more than one call to the facebook API. Try to check if you are closing your windows and if the login function is being called more than once.

Let me know if that works for you. Good luck.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top