Error 2500 when trying to get Facebook Email in Appcelerator Titanium

女生的网名这么多〃 提交于 2019-12-12 05:07:41

问题


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."}

My code is:

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

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

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]

What I do wrong? How to get Email from FB? Any help deeply appreciated.


回答1:


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

Hope it helps.



来源:https://stackoverflow.com/questions/37882708/error-2500-when-trying-to-get-facebook-email-in-appcelerator-titanium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!