[MOD-2270] Appcelerator Titanium Facebook request doesn't return email on iOS
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2016-07-11T13:19:42.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | |
Labels | facebook, module |
Reporter | CREATIVE KAIZEN |
Assignee | Hans Knöchel |
Created | 2016-07-08T15:53:26.000+0000 |
Updated | 2016-07-20T12:08:09.000+0000 |
Description
I am trying to to receive email of user logged in via Facebook. On iOS it reuturns me data without email.
Important:
*This is not account problem (it returns email on Android) nor module configuration error (I can log in/log out and retreive other data)*
Steps to reproduce
var viewClick = function() {
fb.logout();
fb.initialize();
fb.authorize();
};
var facebookLogged = function(e) {
Ti.API.info('results From Event: ' + JSON.stringify(e))
fb.requestWithGraphPath("me?fields=name,email,first_name,last_name", {}, 'GET', function(result) {
// fb.requestWithGraphPath("me", { fields: "name,email,first_name,last_name"}, 'GET', function(result) {
Ti.API.info('results From Graph API: ' + JSON.stringify(result))
var data = JSON.parse(result.result);
Ti.API.info("-- email: " + data.email);
});
};
var window = Ti.UI.createWindow({exitOnClose: true, navBarHidden: true, fullscreen: true, orientationModes: [
Ti.UI.PORTRAIT,
Ti.UI.UPSIDE_PORTRAIT,
],
backgroundColor: '#f0f2f2'
});
var fb = require('facebook');
if(Ti.Platform.osname === 'android') {
window.fbProxy = fb.createActivityWorker({lifecycleContainer: window});
}
//fb.setLoginBehavior(fb.LOGIN_BEHAVIOR_NATIVE);
fb.permissions = ['email'];
window.open();
var view = Ti.UI.createView({
height: 200,
width: 200,
backgroundColor: 'red'
});
view.addEventListener('click', viewClick);
window.add(view);
fb.addEventListener('login', facebookLogged);
Results are:
results From Event: {"success":true,"code":0,"data":"{\"firstName\":\"Eren\",\"lastName\":\"Kars\",\"userID\":\"1498651573764560\",\"middleName\":\"\",\"name\":\"Eren Kars\",\"linkURL\":\"https:\\/\\/www.facebook.com\\/app_scoped_user_id\\/1498651573764560\\/\"}","uid":"1498651573764560","cancelled":false,"bubbles":true,"type":"login","source":{"id":"facebook"},"cancelBubble":false}
results From Graph API: {"result":"{\"id\":\"1498651573764560\",\"last_name\":\"Kars\",\"name\":\"Eren Kars\",\"first_name\":\"Eren\"}","success":true,"path":"me?fields=name,email,first_name,last_name"}
-- email: undefined
There is no problem with configuration/module because:
- I made it working on Android (it returns email),
- It works fine with logging in (both on Android/iOS),
- It returns all the fields except email and gives no errors with Graph API.
Hey there, does the query work in the Graph Explorer? I'm wondering why it does work on Android but not iOS. Thanks!
Hello Hans, Yes it does. If it would not work there than it would not work on Android either. Regards
Ok, so after reading [this StackOverflow](http://stackoverflow.com/questions/29323244/facebook-ios-sdk-4-0how-to-get-user-email-address-from-fbsdkprofile), such parameters need to be passed in the
parameters
object that is represented by the second argument here. So can you try the following:Of course it should behave the same on Android and iOS, but maybe the Android SDK still supports the other way for backwards-compatibility. Ultimately, I think the above method is the proper solution and should work, since we "only" delegate the parameters to the native method. Give it a try, thanks!
Hello Hans, On Android only this approach works (and it is in contrary to documentation):
On iOS none of these two approaches returns email. I tried both (you can check my commented line). If I try your code in return I get:
I just tested it myself, using the below demo-code:
Result:
So I am pretty sure that either your Facebook application is configured incorrectly for iOS, your tiapp.xml is missing some of the keys described [here](https://github.com/appcelerator-modules/ti.facebook) or your application logic overrides the permissions from somewhere else.
Closing for now, since I cannot reproduce it with using the provided test-case.
Adding:
Previosly I had shorter version of strings and it was the cause. Sorry for trouble.