【问题标题】:Error 2500 when trying to get Facebook Email in Appcelerator Titanium尝试在 Appcelerator Titanium 中获取 Facebook 电子邮件时出现错误 2500
【发布时间】: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


【解决方案1】:

我遇到了同样的问题,这就是我所做的,对于 Android,requestWithGraphPath 不像它的 IOS 对应物那样工作,并且文档也没有更新。您需要发送对象中的字段,并且只发送第一个参数中的“我”:

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);
    });
};

希望对你有帮助。

【讨论】:

  • 谢谢。它在 Android 上就像一个魅力。你如何接收 iOS 的电子邮件,因为我在那里遇到了同样的问题。
  • 对于 IOS "me?fields=name,email,first_name,last_name" 工作得很好,你在请求​​响应中得到了什么?
  • 我得到 {"result":"{\"id\":\"1498651573764560\",\"last_name\":\"Kars\",\"name\":\"Eren Kars\",\"first_name\":\"Eren\"}","success":true,"path":"me?fields=name,email,first_name,last_name"}
  • iOS 上的问题是由于未在 tiapp.xml 中添加所有必需的 LSApplicationQueriesSchemes 引起的
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-08-23
  • 1970-01-01
  • 2021-12-11
  • 2016-12-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多