问题
I am using the code from the appcelerator docs like this:
var fb = require('facebook');
fb.addEventListener('login', function(e) {
Ti.API.info("Login event received...");
if (e.success) {
alert('login from uid: '+e.uid+', name: '+ JSON.parse(e.data).name);
}
else if (e.cancelled) {
// user cancelled
alert('cancelled');
}
else {
alert(e.error);
}
});
Ti.API.info("fb authorize...");
fb.permissions = ['public_profile'];
fb.initialize();
fb.authorize();
But the login event is never fired and nothing happens. Anyone have any idea why?
I am using appcelerator studio 5.2.2.GA and iOS 9.3.1 on iPhone.
回答1:
Please read Additional iOS Setup Steps and initialize module:
var fb = require('facebook');
fb.permissions = [FACEBOOK_APP_PERMISSIONS];
fb.initialize();
fb.authorize()
回答2:
I had a similar problem, I fixed it by adding this line before fb.authorize()
var fbBtn = fb.createLoginButton();
But I never add the button to the UI, just calling that method seems to trigger something.
回答3:
Are you testing on physical device or in simulator? Running in simulator can cause such issue, when it will work perfectly on physical device.
来源:https://stackoverflow.com/questions/36627325/fb-authorize-never-give-a-login-event