尝试在 Appcelerator Titanium 中获取 Facebook 电子邮件时出现错误 2500 [英] Error 2500 when trying to get Facebook Email in Appcelerator Titanium
问题描述
我尝试获取通过 Facebook 模块登录的用户的电子邮件地址.但是每次{"error":"出现错误代码2500时都会出错.必须使用活动访问令牌来查询有关当前用户的信息."}
I try to get email address of a user logged in via Facebook Module. But get error every time {"error":"An error code 2500 has occured. An active access token must be used to query information about the current user."}
我的代码是:
var viewClick = function() {
fb.logout();
fb.initialize();
fb.authorize();
};
var facebookLogged = function(e) {
fb.requestWithGraphPath("me?fields=name,email,first_name,last_name", {}, 'GET', function(result) {
Ti.API.info(JSON.stringify(result))
// var data = JSON.parse(e.result);
});
};
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);
我还尝试通过修改 requestWithGraphPath 参数来提供访问令牌代码:
I also tried to provide access token code by modyfing requestWithGraphPath parameters:
fb.requestWithGraphPath("me?fields=name,email,first_name,last_name&access_token=" + e.source.accessToken, {}, 'GET', function(result) {}
但在这种情况下,我得到的信息是 accessToken 格式错误.TiFacebookModule: (main) [117,178060] requestWithGraphPath callback error: Malformed access token [Here is access token value]?access_token=[Here is access token value]
but in such case I get infromation that accessToken is malformed. TiFacebookModule: (main) [117,178060] requestWithGraphPath callback error: Malformed access token [Here is access token value]?access_token=[Here is access token value]
我做错了什么?如何从FB获取电子邮件?任何帮助深表感谢.
What I do wrong? How to get Email from FB? Any help deeply appreciated.
推荐答案
我遇到了同样的问题,这就是我所做的,对于 Android,requestWithGraphPath 不像它的 IOS 版本那样工作,并且文档也没有更新.您需要发送对象中的字段,并且只发送第一个参数中的我":
I had the same problem and this is what I do, for Android the requestWithGraphPath doesn't work like its IOS counterpart and the documentation is not updated either. You need to send the fields in the object and only the "me" in the first parameter:
var facebookLogged = function(e) {
fb.requestWithGraphPath("me", { fields: "name,email,first_name,last_name"}, 'GET', function(result) {
Ti.API.info(JSON.stringify(result))
// var data = JSON.parse(e.result);
});
};
希望有帮助.
这篇关于尝试在 Appcelerator Titanium 中获取 Facebook 电子邮件时出现错误 2500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!