简体   繁体   English

Appcelerator:Android回调登录Facebook不起作用

[英]Appcelerator : Android callback login facebook does not work

In my app, on appcelerator with titanium, I try to login with facebook but callback not working, here is my code : 在我的应用程序中,在钛制的appcelerator上,我尝试使用Facebook登录,但回调不起作用,这是我的代码:

var FB = require('facebook');
FB.forceDialogAuth = true;
FB.initialize();
FB.permissions = [
    'public_profile',
    'user_friends',
    'user_about_me',
    'email',
    'user_birthday',
    'user_hometown',
    'user_likes',
    'user_location'
];

UserManager.loginWithFb(function(){
    checkProfile();
});

In User Manager 在用户管理器中

exports.UserManager.prototype.loginWithFb = function(callback) {
    function facebookLogin(e) {
        console.log('facebook function');
        if (e.success) {
            UserManager.getUser(function(user){
                FB.removeEventListener('login', facebookLogin);
                callback();
            });
        } 
        else if (e.error) {
            console.log(e.error);
        }
    }
    console.log('loginWithFb');
    FB.addEventListener('login', facebookLogin);
    FB.authorize();
    console.log('FB next');
};

It works perfectly on iOs but not on Android. 它可以在iO上完美运行,但不能在Android上运行。

My tiapp.xml is like : 我的tiapp.xml是这样的:

<manifest>
            <uses-permission android:name="android.permission.INTERNET"/>
            <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
            <application android:theme="@style/Theme.AppCompat.NoTitleBar">
                <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
                <activity
                    android:name="com.facebook.FacebookActivity"
                    android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
                    android:label="AppName"
                    android:theme="@android:style/Theme.Translucent.NoTitleBar"
                    />
                <activity
                    android:name="com.facebook.CustomTabActivity"
                    android:exported="true">
                    <intent-filter>
                        <action android:name="android.intent.action.VIEW" />
                        <category android:name="android.intent.category.DEFAULT" />
                        <category android:name="android.intent.category.BROWSABLE" />
                        <data android:scheme="@string/fb_login_protocol_scheme" />
                    </intent-filter>
                </activity>
                <meta-data
                    android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyC-v_Vk5Y_bPlYi4s1M76KFhp81aua1EcA"/>
            </application>
        </manifest>

I have not error just console log statues : - 'loginWithFb' - 'FB next' 我没有错误只是控制台日志雕像:-'loginWithFb'-'FB next'

I don't understand, I read documentation and it's the same way to login with facebook on Android. 我不明白,我阅读了文档,这与在Android上使用Facebook登录的方式相同。

If anybody can help me on this problem 如果有人可以帮助我解决这个问题

Try following steps: 请尝试以下步骤:

1- Remove this: 1-删除此:

FB.forceDialogAuth = true;

2. re-shuffle these lines like this: 2.重新整理这些行,如下所示:

FB.permissions = [
    'public_profile',
    'user_friends',
    'user_about_me',
    'email',
    'user_birthday',
    'user_hometown',
    'user_likes',
    'user_location'
];
FB.initialize();

Initialize must be called after permission is set. 设置权限后,必须调用Initialize。 Finally, before calling authorize(), you need to set proxy worker on Android like this: 最后,在调用authorize()之前,您需要像这样在Android上设置代理工作器:

3- Add window proxy to fb instance: 3-将窗口代理添加到fb实例:

$.yourWindow.fbProxy = fb.createActivityWorker({lifecycleContainer: $.yourWindow});

I tried your solution and it always the same thing. 我尝试了您的解决方案,并且总是一样。

Here is my console logs : 这是我的控制台日志:

[WARN] :   BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] :   chromium: [WARNING:spdy_session.cc(2527)] Received WINDOW_UPDATE for invalid stream 21
[INFO] :   loginWithFb
[INFO] :   FB next
[WARN] :   AwContents: onDetachedFromWindow called when already detached. Ignoring
[WARN] :   BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] :   chromium: [WARNING:keycode_converter.cc(91)] empty code string
[WARN] :   BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] :   IInputConnectionWrapper: getSelectedText on inactive InputConnection
[WARN] :   IInputConnectionWrapper: requestCursorAnchorInfo on inactive InputConnection
[WARN] :   IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
[WARN] :   chromium: [WARNING:keycode_converter.cc(91)] empty code string
[WARN] :   BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990

Is it a problem if my view is created like this : 如果我的视图是这样创建的,是否有问题:

//-- SLIDE 4
    var slide_04 = Ti.UI.createView({
        width:'100%',
        height:'100%',
        backgroundColor:'#44BBA4'
    });

    var label_04 = Ti.UI.createLabel({
        text:"Slide 4",
        color:'#222',
        textAlign:'center',
        font: {
            fontSize:24
        },
        touchEnabled:false
    });
    slide_04.add(label_04);
    scrollableDemo.addView(slide_04);

    slide_04.fbProxy = FB.createActivityWorker({lifecycleContainer: slide_04});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM