Problem Description
I recently discovered an issue on Android when logging into Facebook to use the user-data like name & id. Therefor the login callback returns a "data" object, which needs to be parsed manually on Android, but in iOS you don't need to do anything extra.
Steps to reproduce
- Create a simple project.
- Update app.js with:
var fb = require("facebook");
var win = Ti.UI.createWindow({backgroundColor: "#fff"});
var btn = Ti.UI.createButton({title: "Facebook-Login"});
btn.addEventListener("click", doLogin);
fb.addEventListener("login", debugLogin);
function doLogin() {
fb.appid = "***************";
fb.permissions = ["publish_stream"];
fb.forceDialogAuth = false;
fb.authorize();
}
function debugLogin(e) {
Ti.API.info(JSON.stringify(e.data));
alert(e.data.name); // Doesn't work for android
// var t =JSON.parse(e.data); // Does work for android.
// alert(t.name); // Does work for android.
}
win.add(btn);
win.open();
- Add facebook module in tiapp.xml
- Run on android device
Extra info
The difference in the callbacks are here.
iOS:
https://gist.github.com/hansknoechel/9e63d4b683bd72cc29bd
Android:
https://gist.github.com/hansknoechel/f0f3280fda26f98d52c0
The bug was also discussed 2 years ago in the Q&A:
https://developer.appcelerator.com/question/135341/titaniumfacebook-login-callback---cant-access-user-data-on-android-device
Workaround
The bug can be "fixed" by using a conditional statement like:
var data = (OS_ANDROID) ? JSON.parse(e.data) : e.data;
But a consistent behaviour is clearly the better way.
No comments