FacebookSdk 未启动 android

FacebookSdk not starting android

我已经尝试了教程中的所有内容,所有答案,甚至使用 https://github.com/facebook/facebook-android-sdk/tree/master/samples 中的示例。我在 developers.facebook.com/apps

中尝试过测试应用和普通应用

但我总是得到这个错误 必须在 AndroidManifest.xml 中设置有效的 Facebook 应用程序 ID,或者在初始化 sdk 之前通过调用 FacebookSdk.setApplicationId 来设置。

完整错误:

05-31 22:19:09.798 2895-2895/jonjon.fb1 I/art: Not late-enabling -Xcheck:jni (already on)
05-31 22:19:09.868 2895-2895/jonjon.fb1 W/System: ClassLoader referenced unknown path: /data/app/jonjon.fb1-1/lib/x86_64
05-31 22:19:09.888 2895-2895/jonjon.fb1 I/FacebookInitProvider: Failed to auto initialize the Facebook SDK
                                                                A valid Facebook app id must be set in the AndroidManifest.xml or set by calling FacebookSdk.setApplicationId before initializing the sdk.
                                                                    at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:275)
                                                                    at com.facebook.FacebookSdk.sdkInitialize(FacebookSdk.java:231)
                                                                    at com.facebook.internal.FacebookInitProvider.onCreate(FacebookInitProvider.java:20)
                                                                    at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
                                                                    at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
                                                                    at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
                                                                    at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
                                                                    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
                                                                    at android.app.ActivityThread.-wrap1(ActivityThread.java)
                                                                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
                                                                    at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                    at android.os.Looper.loop(Looper.java:148)
                                                                    at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                    at java.lang.reflect.Method.invoke(Native Method)
                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-31 22:19:09.892 2895-2895/jonjon.fb1 D/AndroidRuntime: Shutting down VM


                                                          --------- beginning of crash
05-31 22:19:09.892 2895-2895/jonjon.fb1 E/AndroidRuntime: FATAL EXCEPTION: main
                                                          Process: jonjon.fb1, PID: 2895
                                                          java.lang.RuntimeException: Unable to get provider com.facebook.accountkit.internal.AccountKitInitProvider: 500: Initialization error: 502: The App Id must be specified in the string resource file as com.facebook.sdk.ApplicationId
                                                              at android.app.ActivityThread.installProvider(ActivityThread.java:5156)
                                                              at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
                                                              at android.app.ActivityThread.-wrap1(ActivityThread.java)
                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                              at android.os.Looper.loop(Looper.java:148)
                                                              at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                           Caused by: 500: Initialization error: 502: The App Id must be specified in the string resource file as com.facebook.sdk.ApplicationId
                                                              at com.facebook.accountkit.internal.Initializer.getRequiredString(Initializer.java:228)
                                                              at com.facebook.accountkit.internal.Initializer.initialize(Initializer.java:113)
                                                              at com.facebook.accountkit.internal.AccountKitController.initialize(AccountKitController.java:592)
                                                              at com.facebook.accountkit.internal.AccountKitInitProvider.onCreate(AccountKitInitProvider.java:31)
                                                              at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
                                                              at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
                                                              at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
                                                              at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) 
                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) 
                                                              at android.app.ActivityThread.-wrap1(ActivityThread.java) 
                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) 
                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                              at android.os.Looper.loop(Looper.java:148) 
                                                              at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
05-31 22:41:18.585 3969-3969/jonjon.fb1 D/AndroidRuntime: Shutting down VM
05-31 22:41:18.585 3969-3969/jonjon.fb1 E/AndroidRuntime: FATAL EXCEPTION: main
                                                          Process: jonjon.fb1, PID: 3969
                                                          java.lang.RuntimeException: Unable to get provider com.facebook.accountkit.internal.AccountKitInitProvider: 500: Initialization error: 503: The Client Token must be specified in the string resource file as com.facebook.accountkit.ClientToken
                                                              at android.app.ActivityThread.installProvider(ActivityThread.java:5156)
                                                              at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748)
                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688)
                                                              at android.app.ActivityThread.-wrap1(ActivityThread.java)
                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405)
                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                              at android.os.Looper.loop(Looper.java:148)
                                                              at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                           Caused by: 500: Initialization error: 503: The Client Token must be specified in the string resource file as com.facebook.accountkit.ClientToken
                                                              at com.facebook.accountkit.internal.Initializer.getRequiredString(Initializer.java:228)
                                                              at com.facebook.accountkit.internal.Initializer.initialize(Initializer.java:118)
                                                              at com.facebook.accountkit.internal.AccountKitController.initialize(AccountKitController.java:592)
                                                              at com.facebook.accountkit.internal.AccountKitInitProvider.onCreate(AccountKitInitProvider.java:31)
                                                              at android.content.ContentProvider.attachInfo(ContentProvider.java:1748)
                                                              at android.content.ContentProvider.attachInfo(ContentProvider.java:1723)
                                                              at android.app.ActivityThread.installProvider(ActivityThread.java:5153)
                                                              at android.app.ActivityThread.installContentProviders(ActivityThread.java:4748) 
                                                              at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4688) 
                                                              at android.app.ActivityThread.-wrap1(ActivityThread.java) 
                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1405) 
                                                              at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                              at android.os.Looper.loop(Looper.java:148) 
                                                              at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                              at java.lang.reflect.Method.invoke(Native Method) 
                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

添加

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //initialize Facebook SDK
    FacebookSdk.sdkInitialize(getApplicationContext());
    if (BuildConfig.DEBUG) {
        FacebookSdk.setIsDebugEnabled(true);
        FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
    }

    setContentView(R.layout.activity_main); }

初始化库失败。 我认为 logcat 中所说的解决方案是在 strings.xml 中添加一个名称为

的字符串

com.facebook.sdk.ApplicationId

作为价值,你必须把代币 然后你可以调用

FacebookSdk.sdkInitialize(this); 

在onCreate

因为 FacebookSdk.sdkInitialize(getApplicationContext()); 已弃用。您可以使用这些方法来初始化 facebookSDK

FacebookSdk.fullyInitialize();
AppEventsLogger.activateApp(application);

工作正常

添加

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.activity_main);

    //initialize Facebook SDK
 FacebookSdk.setClientToken("XXXXXXXXXXXXX");
    FacebookSdk.sdkInitialize(getApplicationContext());
    if (BuildConfig.DEBUG) {
        FacebookSdk.setIsDebugEnabled(true);
        FacebookSdk.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
    } }