FacebookSdk.sdkInitialize (Context) is deprecated

匿名 (未验证) 提交于 2019-12-03 02:16:02

问题:

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?

回答1:

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.



回答2:

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.



回答3:

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());     } } 


回答4:

I had the same issu and this is how I've resolve it : Put this line of code in your manifest file

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

https://developers.facebook.com/docs/android/getting-started Thanks



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!