Ozan
Ozan

Reputation: 1401

FacebookSdk.sdkInitialize (Context) is deprecated

I'm using facebook-android-sdk-4.19.0 in Android Studio and I followed the Facebook quick start guide at https://developers.facebook.com/docs/android/getting-started (Click on the Quick Start button to sign in with your own facebook account). In the guide, it's told to copy&paste the following code in the snippet to track app logs

import com.facebook.FacebookSdk;
import com.facebook.appevents.AppEventsLogger;

public class MyApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(this);
    }
}

However, when I copy pasted the code in android studio, it appears that all of the FacebookSdk.sdkInitialize() methods are deprecated. The documentation here https://developers.facebook.com/docs/reference/android/current/class/FacebookSdk/ tells nothing about what method to use to initialize the sdk instead of sdkInitialize(). What method should I use?

Upvotes: 115

Views: 70259

Answers (6)

Aditya Nandardhane
Aditya Nandardhane

Reputation: 1413

Android :

Add this line in AndroidManifest.xml

<meta-data android:name="com.facebook.sdk.ClientToken" android:value="YOUR-CLIENT-TOKEN-HERE" />

For client ID Please check the below link-

https://developers.facebook.com/apps/Your_App_ID/settings/advanced/

Upvotes: 4

Rahul Khatri
Rahul Khatri

Reputation: 1622

FacebookSdk.sdkInitialize(getApplicationContext());

No need of this method as Facebook doc says: This function initializes the Facebook SDK is called automatically on app start up if the proper entries are listed in the AndroidManifest, such as the facebook app id. Automatic event logging from 'activateApp' can be controlled via the 'com.facebook.sdk.AutoLogAppEventsEnabled' manifest setting.

Upvotes: 2

Sahil Patel
Sahil Patel

Reputation: 734

My requirement was to disable autoInit at app launch and initialise it from Activity's onCreate method. AutoInit before app launch was causing my flutter app to take time to start on slow network connections.

  1. Disable AutoInit from manifest

    <meta-data android:name="com.facebook.sdk.AutoInitEnabled"
        android:value="false"/>
    
  2. Initialise Fb sdk in activity's onCreate method

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

Upvotes: 9

VaibhavBhosale
VaibhavBhosale

Reputation: 275

FacebookSdk.sdkInitialize(getApplicationContext()); 

This method is deprecated so simply delete this line of code in your class. because according to the latest Facebook we now don't need to initialize the SDK manually, it gets initialize by itself.

Upvotes: 16

Rakesh Yadav
Rakesh Yadav

Reputation: 1985

So Instead of calling the deprecated methods you can call AppEventsLogger.activateApp(Application) inside your application class's onCreate()

public class MyApplication extends Application{

    @Override
    public void onCreate() {
        super.onCreate();
        AppEventsLogger.activateApp(getApplication());
    }
}

Upvotes: 4

Yupi
Yupi

Reputation: 4470

From the documentation about upgrading SDK:

The Facebook SDK is now auto initialized on Application start. If you are using the Facebook SDK in the main process and don't need a callback on SDK initialization completion you can now remove calls to FacebookSDK.sdkInitialize. If you do need a callback, you should manually invoke the callback in your code.

Refer to: https://developers.facebook.com/docs/android/upgrading-4x

UPDATE

In SDK 4.22 the title, description, caption and image field of FBSDKShareLinkContent are deprecated. Consider removing them from usage.

Upvotes: 142

Related Questions