0

when I try to initialize the FacebookSdk it always deprecates the function call and when I build/run my application it exits with the error "Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.setApplicationId("165020910744675");
    FacebookSdk.sdkInitialize(this);
    setContentView(R.layout.activity_main);

    callbackManager = CallbackManager.Factory.create();
    loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setHeight(100);
    loginButton.setTextColor(Color.WHITE);
    loginButton.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    loginButton.setCompoundDrawablePadding(0);


    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
        @Override
        public void onSuccess(LoginResult loginResult) {
            Log.d(TAG,"success!!! go home.");
        }

        @Override
        public void onCancel() {
            Log.d(TAG,"cancel!!! don't go home.");
        }

        @Override
        public void onError(FacebookException error) {

        }
    });

If we remove the FacebookSdk.sdkInitialize() function (like the FB API says), it causes the same error.

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
  • 4
    Possible duplicate of [how to implement facebook login in android using facebook sdk 4.7](https://stackoverflow.com/questions/33584031/how-to-implement-facebook-login-in-android-using-facebook-sdk-4-7) – InsaneCat Oct 10 '17 at 05:18

1 Answers1

0

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

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