Appcelerator Facebook module doesn't fire logi

2019-06-13 20:10发布

问题:

Appcelerator 5.2.0 Facebook Module (Android) doesn't fire 'login' event after successful logged in.

What could it be?

var FB = require('facebook');
FB.initialize();
FB.permissions = ['public_profile', 'email', 'user_events'];
FB.forceDialogAuth = false;
FB.addEventListener('login', function() {
     alert('login');
});
FB.authorize();

Thanks!

回答1:

Hello Oxana,

Additional Android Setup Steps Since Facebook module v4.0.0, for the Android platform, you need to:

  • Add the Facebook Login activity to the Android manifest
  • Add the Facebook App ID to the Android resources string.xml file
  • Create a Facebook proxy and associate it with the current active activity (you need)

Manifest:

<ti:app>
    <android xmlns:android="http://schemas.android.com/apk/res/android">
        <manifest>
            <application>
                <activity android:label="@string/app_name"
                    android:name="com.facebook.LoginActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
                <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
            </application>
        </manifest>
    </android>
<ti:app>

Add the Facebook App ID to Android Resources

Add a string element to the /platform/android/res/values/strings.xml file with the name attribute set to facebook_app_id and the node text set to your Facebook App ID. Create the file if it does not exist.

<resources>
    <string name="facebook_app_id">FACEBOOK_APP_ID</string>
</resources>

**I think this step is that you need =D **

Create a Facebook Proxy

Use the createActivityWorker() method to create a Facebook proxy. Pass the method a dictionary with the lifecycleContainer property set to the current active instance of a standalone Window (window not contained in a tab group) or TabGroup. Create the proxy before calling the open() method on either the window or tab group.

The Facebook module needs to hook into the lifecycle events of the current active activity in order to synchronize its state between various activities in the application, for example, to update the label of the Login button when the user logs in or out of Facebook.

Attach the proxy to the Window or TabGroup object, so it does not get garbage collected.

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

Documentation: Facebook module