【发布时间】:2023-03-08 17:13:01
【问题描述】:
我尝试获取通过 Facebook 模块登录的用户的电子邮件地址。但是每次都会报错 {"error":"An error code 2500 has been occurred. 必须使用活动访问令牌来查询当前用户的信息。"}
我的代码是:
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 参数来提供访问令牌代码:
fb.requestWithGraphPath("me?fields=name,email,first_name,last_name&access_token=" + e.source.accessToken, {}, 'GET', function(result) {}
但在这种情况下,我得到的信息是 accessToken 格式错误。 TiFacebookModule: (main) [117,178060] requestWithGraphPath 回调错误:格式错误的访问令牌 [这里是访问令牌值]?access_token=[这里是访问令牌值]
我做错了什么?如何从 FB 获取电子邮件?任何帮助都深表感谢。
【问题讨论】:
-
ps:不要发布你的令牌
-
这是假帐户(仅用于测试应用程序)所以没什么大不了的:)。但我会清理它。
-
您究竟在哪里获取和传递身份验证令牌?
-
@developer82:访问令牌和用户 ID 通过 facebookLogged 函数中的返回对象 (e) 发送。触发“登录”事件时调用此函数。正如我写的那样,我做了两种方法而不发送访问令牌(错误 2500):
fb.requestWithGraphPath("me?fields=name,email,first_name,last_name", {}, 'GET', function(result) {或发送令牌(格式错误的访问令牌错误):fb.requestWithGraphPath("me?fields=name,email,first_name,last_name&access_token=" + e.source.accessToken, {}, 'GET', function(result) {
标签: facebook facebook-graph-api appcelerator titanium-mobile appcelerator-titanium