I have developed a mobile app using Titanium alloy 3.2.3GA. I am using facebook authentication as an option for user to sign in. However the facebook login event is not fired when facebook authenticated successfully. I know this kind of question has been answered but still no solve for me. Below is my code:
//event for facebook login button
$.facebook_login_option.addEventListener('click', function(e){
common_util.showConfirmDialog('Confirm to login via facebook', function(e){
facebookLogin();
});
});
//event for facebook login event, make sure the event is added once
if(Alloy.Globals.ADD_FACEBOOK_LOGIN_EVENT==false){
facebook.addEventListener('login', function(e) {
if (e.success) {
facebook.requestWithGraphPath('me', {}, 'GET', function(e) {
if (e.success) {
var data = JSON.parse(e.result);
Ti.API.debug(e.result);
var access_token = Ti.Facebook.accessToken;
var user_id = data.id;
var name = data.name;
var email = data.email;
Ti.API.debug('access_token=' + access_token);
Ti.API.debug('user_id=' + user_id);
Ti.API.debug('name=' + name);
Ti.API.debug('email=' + email);
//..... my server side user authentication logic here .....
} else if (e.error) {
Ti.API.warn('failed to sign in with facebook due to ' + e.error);
alert('Failed to sign in with facebook due to error');
} else {
Ti.API.warn('Unknown response');
alert('Failed to sign in with facebook due to unknown response');
}
});
} else if (e.cancelled) {
alert("You have canceled the facebook sign in");
} else if (e.error) {
Ti.API.warn('failed to sign in with facebook due to ' + e.error);
alert('Failed to sign in with facebook');
}
});
Alloy.Globals.ADD_FACEBOOK_LOGIN_EVENT = true;
}
//function for facebook login
function facebookLogin() {
try {
facebook.appid = Alloy.Globals.getSetting('ti.facebook.appid');
facebook.permissions = ['publish_stream'];
facebook.forceDialogAuth = false;
Ti.API.info("=================== start: facebook authorization ===================");
facebook.authorize();
} catch(error) {
alert('Failed to login due to error '+error);
}
}
The login event in mentioned code above is not fired in android. IOS simulator work perfectly.
Checked with facebook app settings, key hashes should be correct, as i tested with incorrect key hashes, facebook authentication will prompt me the invalid key error.
Checked with reported jira from titanium, some even said should no set exitOnClose=true in window. I have changed to exitOnClose=false like below:
<Window id="login" class="container" exitOnClose="false" navBarHidden="true" fullscreen="true">
But there is only thing i am not very sure is the class name in facebook settings, where i suppose copy the value from AndroidManifest.xml is correct.
<application android:icon="@drawable/appicon" android:label="Loyal With" android:name="[Class name to copy]" android:debuggable="false">
Anything i missed or any workaround. Please help on this matter.
0 comments:
Post a Comment