Facebook Sdk Has Not Been Initialized FacebookSdk.sdkInitialize()

前端 未结 8 1299
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 23:55

Hey I know this was asked before, but none of the solutions seem to help. I\'m using first time Facebook SDK in my application.

What I\'ve tried:

I had tried

相关标签:
8条回答
  • 2020-12-05 00:19

    After checking the documentation I found that they are asking to initialize FacebookSdk in Application class onCreate() Method.

    Snap code from Facebook doc:

      public class MyApplication extends Application {
     // Updated your class body:
     @Override
     public void onCreate() {
        super.onCreate();
        // Initialize the SDK before executing any other operations,
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(this);
       }
     }
    
    0 讨论(0)
  • 2020-12-05 00:19

    Use Initialise Callback Constructor like this:

        Handler mHandler = new Handler();
                FacebookSdk.InitializeCallback initializeCallback = new FacebookSdk.InitializeCallback() {
                    @Override
                    public void onInitialized() {
    
                        mHandler.post(new Runnable() {
                            @Override
                            public void run() {
                                //UI Code Here
                            }
                        });
                    }
                };
        //before setContentView()   
     FacebookSdk.sdkInitialize(getActivity().getApplicationContext(),initializeCallback);
    
    0 讨论(0)
  • 2020-12-05 00:26

    There is a reason why sdkInitialize() is deprecated.

    Go to your manifest file within the android folder and add following

    <meta-data android:name="com.facebook.sdk.ApplicationId"
          android:value="@string/facebook_app_id"/>
    

    After that append in your strings.xml file (res/values/strings.xml) the string entry:

    <string name="facebook_app_id">APP_ID</string>
    

    Close your Metro Builder and rebuild your Project using react-native run-android

    0 讨论(0)
  • 2020-12-05 00:31

    Problem

    While integrating Android SDK for a react-native project, I had finished the Android with React Native v0.30+ Project Configuration guide, and ran react-native run-android and then got this screen:

    I learned that FacebookSdk.sdkInitialize is deprecated. see here

    After some searching, I realized that the guide did not contain the steps to add the Facebook App ID for my app.

    Solution

    1. Open android/app/src/main/AndroidManifest.xml file and look in the <application> tag to confirm that this meta-data tag exists:

      <meta-data android:name="com.facebook.sdk.ApplicationId"
                android:value="@string/facebook_app_id"/>
      
    2. Open android/app/src/main/res/values/strings.xml file and confirm that this there is a "facebook_app_id" string tag with your app id as the value:

      <string name="facebook_app_id">YOUR_APP_ID_HERE</string>
      
    3. Run react-native run-android.

    These are the steps that worked for me.

    0 讨论(0)
  • 2020-12-05 00:34

    Follow only 2 Step and your Facebook Sdk iw working in React Native

        <meta-data android:name="com.facebook.sdk.ApplicationId"
                  android:value="@string/facebook_app_id"/>
    
        <string name="facebook_app_id">YOUR_APP_ID_HERE</string>
    

    Don't Need this b'coz Its Deprecated Now

      FacebookSdk.sdkInitialize(getApplicationContext());
    
    0 讨论(0)
  • 2020-12-05 00:42

    You don't need to use FacebookSdk.sdkInitialize anymore. Check if your:

    <meta-data android:name="com.facebook.sdk.ApplicationId"
                android:value="@string/facebook_app_id"/>
    

    is inside <application> tag.

    0 讨论(0)
提交回复
热议问题