fb.authorize() never give a login event

左心房为你撑大大i 提交于 2020-01-06 08:11:33

问题


I am using the code from the appcelerator docs like this:

var fb = require('facebook');

fb.addEventListener('login', function(e) {

    Ti.API.info("Login event received...");

    if (e.success) {
        alert('login from uid: '+e.uid+', name: '+ JSON.parse(e.data).name);
    }
    else if (e.cancelled) {
        // user cancelled
        alert('cancelled');
    }
    else {
        alert(e.error);
    }
});

Ti.API.info("fb authorize...");
fb.permissions = ['public_profile'];
fb.initialize();
fb.authorize();

But the login event is never fired and nothing happens. Anyone have any idea why?

I am using appcelerator studio 5.2.2.GA and iOS 9.3.1 on iPhone.


回答1:


Please read Additional iOS Setup Steps and initialize module:

var fb = require('facebook');
 fb.permissions = [FACEBOOK_APP_PERMISSIONS];
 fb.initialize();
 fb.authorize()



回答2:


I had a similar problem, I fixed it by adding this line before fb.authorize()

var fbBtn = fb.createLoginButton();

But I never add the button to the UI, just calling that method seems to trigger something.




回答3:


Are you testing on physical device or in simulator? Running in simulator can cause such issue, when it will work perfectly on physical device.



来源:https://stackoverflow.com/questions/36627325/fb-authorize-never-give-a-login-event

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