【发布时间】:2016-07-02 11:55:14
【问题描述】:
我正在尝试接收通过 Facebook 登录的用户的电子邮件。我让它在 Android 上运行,但在 iOS 上它返回我没有电子邮件的用户数据。
我的代码是:
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
配置/模块没有问题,因为:
- 我让它在 Android 上运行(它返回电子邮件),
- 在登录时可以正常工作(在 Android/iOS 上),
- 它返回除电子邮件以外的所有字段,并且使用 Graph API 没有错误。
提前感谢您的帮助。
【问题讨论】:
-
我也在使用“电子邮件”权限,但我认为用户必须允许 Facebook 和应用程序查看他们的电子邮件地址。有时它有效,有时无效。如果我用我的 facebook 帐户尝试它,它可以工作,但我有一些用户没有这些信息
-
@CarlosHenriqueLustosa:我认为这不是问题,因为在 Android 上,同一个帐户会返回电子邮件。
-
在 facebook v 2.0 api 的电子邮件 ID 变为可选后,如果用户将其设为私有,则电子邮件不应在 api 中检索,但您会获得 fb id。
标签: facebook titanium appcelerator titanium-mobile appcelerator-titanium