Titanium JIRA Archive
Appcelerator Modules (MOD)

[MOD-2270] Appcelerator Titanium Facebook request doesn't return email on iOS

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionCannot Reproduce
Resolution Date2016-07-11T13:19:42.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsFacebook
Labelsfacebook, module
ReporterCREATIVE KAIZEN
AssigneeHans Knöchel
Created2016-07-08T15:53:26.000+0000
Updated2016-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.

Comments

  1. Hans Knöchel 2016-07-08

    Hey there, does the query work in the Graph Explorer? I'm wondering why it does work on Android but not iOS. Thanks!
  2. CREATIVE KAIZEN 2016-07-09

    Hello Hans, Yes it does. If it would not work there than it would not work on Android either. Regards
  3. Hans Knöchel 2016-07-11

    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:
       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);
           });
       
    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!
  4. CREATIVE KAIZEN 2016-07-11

    Hello Hans, On Android only this approach works (and it is in contrary to documentation):
       fb.requestWithGraphPath("me", {"fields": "name,email,first_name,last_name"}, 'GET', function(result) {
       
    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:
       [INFO] :   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}
       [INFO] :   results From Graph API: {"result":"{\"id\":\"1498651573764560\",\"last_name\":\"Kars\",\"name\":\"Eren Kars\",\"first_name\":\"Eren\"}","success":true,"path":"me"}
       [INFO] :   -- email: undefined
       
  5. Hans Knöchel 2016-07-11

    I just tested it myself, using the below demo-code:
       var fb = require("facebook");
       
       var win = Ti.UI.createWindow({
           backgroundColor : "#fff"
       }); 
       
       var btn = Ti.UI.createButton({
           title : "Do Graph Request"
       });
       
       btn.addEventListener("click", function() {
           fb.logout();
       
           fb.permissions = ['email'];
           fb.initialize(); 
           fb.authorize();
       });
       
       fb.addEventListener('login', function(e) {
           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);
          });
       });
       
       win.add(btn);
       win.open();
       
    Result:
       [INFO]  results From Graph API: {"result":"{\"email\":\"xxxxxx\",\"id\":\"272367196277712\",\"last_name\":\"App\",\"name\":\"Demo App\",\"first_name\":\"Demo\"}","success":true,"path":"me"}
       [INFO]  -- email: xxxxxx
       
    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.
  6. Hans Knöchel 2016-07-11

    Closing for now, since I cannot reproduce it with using the provided test-case.
  7. CREATIVE KAIZEN 2016-07-20

    Adding:
       <key>LSApplicationQueriesSchemes</key>
                       <array>
                           <string>fbapi</string>
                           <string>fbapi20130214</string>
                           <string>fbapi20130410</string>
                           <string>fbapi20130702</string>
                           <string>fbapi20131010</string>
                           <string>fbapi20131219</string>
                           <string>fbapi20140410</string>
                           <string>fbapi20140116</string>
                           <string>fbapi20150313</string>
                           <string>fbapi20150629</string>
                           <string>fbapi20160328</string>
                           <string>fbauth</string>
                           <string>fbauth2</string>
                           <string>fb-messenger-api20140430</string>
                       </array>
       
    Previosly I had shorter version of strings and it was the cause. Sorry for trouble.

JSON Source