Appcelerator Titanium Facebook请求不会返回电子邮件

时间:2016-07-02 11:55:15

标签: facebook titanium appcelerator titanium-mobile appcelerator-titanium

我正在尝试接收通过Facebook登录的用户的电子邮件。我让它在Android上工作,但在iOS上,它返回user user而不发送电子邮件。

我的代码是:

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 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

配置/模块没有问题,因为:

  1. 我让它在Android上运行(它返回电子邮件),
  2. 它可以正常登录(在Android / iOS上),
  3. 它会返回除电子邮件之外的所有字段,并且不会使用图谱API提供任何错误。
  4. 提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

原因是我放了一些LSApplicationQueriesSchemes字符串,但似乎我没有添加所有必需的字符串。我添加了所有这些(超过了所需的Appcelerator文档),现在它可以正常工作。

<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>