[AC-2190] Android: Facebook login occasionally hangs
| GitHub Issue | n/a | 
|---|---|
| Type | Bug | 
| Priority | n/a | 
| Status | Closed | 
| Resolution | Cannot Reproduce | 
| Resolution Date | 2013-09-09T20:50:22.000+0000 | 
| Affected Version/s | n/a | 
| Fix Version/s | n/a | 
| Components | Appcelerator Modules, Titanium SDK & CLI | 
| Labels | facebook, module | 
| Reporter | Mark Mokryn | 
| Assignee | Mauro Parra-Miranda | 
| Created | 2013-06-18T11:41:02.000+0000 | 
| Updated | 2016-03-08T07:41:10.000+0000 | 
Description
	*Steps to reproduce*
1. Build for Android device 
2. Click login button, wait for login event
3. Click logout button
4. Click back button to close app
5. Repeat above steps a few times. After a few iterations (usually just 2 or 3), clicking the login button seems to have no effect.
6. At this point, check the Android logs. I see the following message: com.facebook.Session Should not pass a read permission (email) to a request for publish or manage authorization . Something is clearly wrong, as my app never asked for anything besides email permission.
7. At this point, only closing the app enables recovery. This causes a major usability problem on Android.
*index.js*
var loggedIn = undefined;
var fb = require('facebook');
fb.appid = 'YOUR_APP_ID';
fb.permissions = ['email'];
fb.forceDialogAuth = false;
function doLogin(e) {
	fb.authorize();
}
function doLogout(e){
	fb.logout();
}  
function loggedInState() {
	$.initLabel.visible = false;
	$.logoutBtn.visible = true;
	$.loginBtn.visible = false;	
	Ti.API.info('Access token in case we need to debug: ' + fb.accessToken);	
}
function loggedOutState() {
	$.initLabel.visible = false;
	$.logoutBtn.visible = false;
	$.loginBtn.visible = true;	
}
fb.addEventListener('logout', function() {
	loggedOutState();
});
fb.addEventListener('login', function(e) {
	Ti.API.info('Facebook login event, data:' + JSON.stringify(e.data) + ' cancelled: ' + e.cancelled + 
		' error: ' + e.error + ' type: ' + e.type + ' uid: ' + e.uid + ' success: ' + e.success);
	if (e.success) {
		loggedInState();
		alert('Login success, see console logs for user data');
	} else if (e.error) {
		alert ('Login error: ' + e.error);
		loggedOutState();
	} else if (e.cancelled) { // do nothing
		alert('Login cancelled');
		loggedOutState();
	} else {
		alert('no success, no error, and not cancelled... assume loggedOutState');
		loggedOutState();
	}
});
loggedIn = fb.getLoggedIn();
Ti.API.info('logged in: ' + loggedIn); 
if (loggedIn) {
	loggedInState();
}
if (loggedIn === false) {
	loggedOutState();
}
$.index.open();
 
*index.xml*
 
<Alloy>
	<Window class="container">
		<Label id="initLabel">This appears only when login state is undefined</Label>
		<Button id="loginBtn" onClick="doLogin">Facebook Login</Button>
		<Button id="logoutBtn" onClick="doLogout">Facebook Logout</Button>
	</Window>
</Alloy>
 
*index.tss*
".container": {
	backgroundColor:"white"
},
"#initLabel": {
	width: Ti.UI.SIZE,
	height: Ti.UI.SIZE,
	color: "#000",
	visible: true
} ,
"#loginBtn": {
	visible: false
},
"#logoutBtn": {
visible: false
}
*tiapp.xml extract*
<id>com.test.ti</id> <!-- make sure this matches your Facebook app config -->
<property name="ti.facebook.appid">YOUR_APP_ID</property>
...
    <modules>
    	<!-- Add the appropriate line(s) to your modules section -->
    	<module platform="android">facebook</module>
    	<module platform="iphone">facebook</module>
    </modules>
Tested this, looks working just fine.
I have the same issue on 3.2.0 with fb module 3.0.2. When clicking the button the log says "W/com.facebook.Session: Should not pass a read permission (email) to a request for publish or manage authorization" and no auth popup appears. The code: Alloy.Globals.Facebook = require('facebook'); Alloy.Globals.Facebook.appid = 'xxx'; Alloy.Globals.Facebook.permissions = ['email']; Alloy.Globals.Facebook.forceDialogAuth = false;