I am integrating Facebook login and share. In login controller login functionality is working fine. But after login it is redirected to share controller in which share is implemented. . But my problem is, if a user logged in to the app without using Facebook login (direct login), he has to login to Facebook from share page . At this point login event defined in login controller is fired, and again redirects the user to share page. I don’t want to trigger the login event defined in login controller. Instead trigger the one defined in share controller itself.
login.js // controller
var fb = "";
fb = require('facebook');
fb.appid = “**********”;
fb.permissions = ["email", "public_profile"];
function loginWithFb() {
fb.forceDialogAuth = true;
if (Ti.Network.online) {
if (fb.loggedIn) {
faceBookHandler();
} else {
fb.authorize();
}
} else {
alert('There is no Internet connection. Please retry when connectivity is restored.');
}
}
fb.addEventListener('login', function(e) {
if (e.success) {
faceBookHandler()
}
});
function faceBookHandler() {
$.loginWindow.close();
Alloy.createController('share').getView().open();
}
share.js
var facebookShare = function(msg,showRequestResult){
var fb = "";
var fb = require('facebook');
fb.appid = ********;
fb.permissions = ['publish_stream'];
fb.forceDialogAuth = true;
if (Ti.Network.online) {
// The activity indicator must be added to a window or view for it to appear
if (fb.loggedIn) {
var data = {
Name : ‘xyxz,
message : msg
};
fb.requestWithGraphPath('me/feed', data, "POST", showRequestResult);
} else {
fb.authorize();
}
} else {
ui.showAlert('An error occurred while connecting to Facebook');
fb = null;
}
};
$.shareBtn.addEventListener("click”,function(e){
facebookShare(fbMessage,showRequestResult);
});
function showRequestResult(e) {
if (e.success) {
alert(“posted”);
}
}
Please help me to solve this issue